📄 resultsetregressiontest.java
字号:
asObject = this.rs.getObject(1); assertEquals("java.lang.String", asObject.getClass().getName()); this.rs.close(); createTable("testBug8868_2", "(field1 CHAR(4) CHARACTER SET BINARY)"); this.stmt .executeUpdate("INSERT INTO testBug8868_2 VALUES ('abc')"); this.rs = this.stmt .executeQuery("SELECT field1 FROM testBug8868_2"); rsmd = this.rs.getMetaData(); assertEquals("[B", rsmd.getColumnClassName(1)); this.rs.next(); asObject = this.rs.getObject(1); assertEquals("[B", asObject.getClass().getName()); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } } /** * Tests fix for BUG#9437, IF() returns type of [B or java.lang.String * depending on platform. Fixed earlier, but in here to catch if it ever * regresses. * * @throws Exception * if the test fails. */ public void testBug9437() throws Exception { String tableName = "testBug9437"; if (versionMeetsMinimum(4, 1, 0)) { try { createTable( tableName, "(" + "languageCode char(2) NOT NULL default ''," + "countryCode char(2) NOT NULL default ''," + "supported enum('no','yes') NOT NULL default 'no'," + "ordering int(11) default NULL," + "createDate datetime NOT NULL default '1000-01-01 00:00:03'," + "modifyDate timestamp NOT NULL default CURRENT_TIMESTAMP on update" + " CURRENT_TIMESTAMP," + "PRIMARY KEY (languageCode,countryCode)," + "KEY languageCode (languageCode)," + "KEY countryCode (countryCode)," + "KEY ordering (ordering)," + "KEY modifyDate (modifyDate)" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); this.stmt.executeUpdate("INSERT INTO " + tableName + " (languageCode) VALUES ('en')"); String alias = "someLocale"; String sql = "select if ( languageCode = ?, ?, ? ) as " + alias + " from " + tableName; this.pstmt = this.conn.prepareStatement(sql); int count = 1; this.pstmt.setObject(count++, "en"); this.pstmt.setObject(count++, "en_US"); this.pstmt.setObject(count++, "en_GB"); this.rs = this.pstmt.executeQuery(); assertTrue(this.rs.next()); Object object = this.rs.getObject(alias); if (object != null) { assertEquals("java.lang.String", object.getClass() .getName()); assertEquals("en_US", object.toString()); } } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } if (this.pstmt != null) { this.pstmt.close(); this.pstmt = null; } } } } public void testBug9684() throws Exception { if (versionMeetsMinimum(4, 1, 9)) { String tableName = "testBug9684"; try { createTable(tableName, "(sourceText text character set utf8 collate utf8_bin)"); this.stmt.executeUpdate("INSERT INTO " + tableName + " VALUES ('abc')"); this.rs = this.stmt.executeQuery("SELECT sourceText FROM " + tableName); assertTrue(this.rs.next()); assertEquals("java.lang.String", this.rs.getString(1) .getClass().getName()); assertEquals("abc", this.rs.getString(1)); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } } /** * Tests fix for BUG#10156 - Unsigned SMALLINT treated as signed * * @throws Exception * if the test fails. */ public void testBug10156() throws Exception { String tableName = "testBug10156"; try { createTable(tableName, "(field1 smallint(5) unsigned, " + "field2 tinyint unsigned," + "field3 int unsigned)"); this.stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (32768, 255, 4294967295)"); this.rs = this.conn.prepareStatement( "SELECT field1, field2, field3 FROM " + tableName) .executeQuery(); assertTrue(this.rs.next()); assertEquals(32768, this.rs.getInt(1)); assertEquals(255, this.rs.getInt(2)); assertEquals(4294967295L, this.rs.getLong(3)); assertEquals(String.valueOf(this.rs.getObject(1)), String .valueOf(this.rs.getInt(1))); assertEquals(String.valueOf(this.rs.getObject(2)), String .valueOf(this.rs.getInt(2))); assertEquals(String.valueOf(this.rs.getObject(3)), String .valueOf(this.rs.getLong(3))); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } public void testBug10212() throws Exception { String tableName = "testBug10212"; try { createTable(tableName, "(field1 YEAR(4))"); this.stmt.executeUpdate("INSERT INTO " + tableName + " VALUES (1974)"); this.rs = this.conn.prepareStatement( "SELECT field1 FROM " + tableName).executeQuery(); ResultSetMetaData rsmd = this.rs.getMetaData(); assertTrue(this.rs.next()); assertEquals("java.sql.Date", rsmd.getColumnClassName(1)); assertEquals("java.sql.Date", this.rs.getObject(1).getClass() .getName()); this.rs = this.stmt.executeQuery("SELECT field1 FROM " + tableName); rsmd = this.rs.getMetaData(); assertTrue(this.rs.next()); assertEquals("java.sql.Date", rsmd.getColumnClassName(1)); assertEquals("java.sql.Date", this.rs.getObject(1).getClass() .getName()); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests fix for BUG#11190 - ResultSet.moveToCurrentRow() fails to work when * preceeded with .moveToInsertRow(). * * @throws Exception * if the test fails. */ public void testBug11190() throws Exception { createTable("testBug11190", "(a CHAR(4) PRIMARY KEY, b VARCHAR(20))"); this.stmt .executeUpdate("INSERT INTO testBug11190 VALUES('3000','L'),('3001','H'),('1050','B')"); Statement updStmt = null; try { updStmt = this.conn .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); this.rs = updStmt.executeQuery("select * from testBug11190"); assertTrue("must return a row", this.rs.next()); String savedValue = this.rs.getString(1); this.rs.moveToInsertRow(); this.rs.updateString(1, "4000"); this.rs.updateString(2, "C"); this.rs.insertRow(); this.rs.moveToCurrentRow(); assertEquals(savedValue, this.rs.getString(1)); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } if (updStmt != null) { updStmt.close(); } } } /** * Tests fix for BUG#12104 - Geometry types not handled with server-side * prepared statements. * * @throws Exception * if the test fails */ public void testBug12104() throws Exception { if (versionMeetsMinimum(4, 1)) { createTable("testBug12104", "(field1 GEOMETRY) ENGINE=MyISAM"); try { this.stmt .executeUpdate("INSERT INTO testBug12104 VALUES (GeomFromText('POINT(1 1)'))"); this.pstmt = this.conn .prepareStatement("SELECT field1 FROM testBug12104"); this.rs = this.pstmt.executeQuery(); assertTrue(this.rs.next()); System.out.println(this.rs.getObject(1)); } finally { } } } /** * Tests fix for BUG#13043 - when 'gatherPerfMetrics' is enabled for servers < * 4.1.0, a NPE is thrown from the constructor of ResultSet if the query * doesn't use any tables. * * @throws Exception * if the test fails */ public void testBug13043() throws Exception { if (!versionMeetsMinimum(4, 1)) { Connection perfConn = null; try { Properties props = new Properties(); props.put("gatherPerfMetrics", "true"); // this property is // reported as the cause // of // NullPointerException props.put("reportMetricsIntervalMillis", "30000"); // this // property // is // reported // as the // cause of // NullPointerException perfConn = getConnectionWithProps(props); perfConn.createStatement().executeQuery("SELECT 1"); } finally { if (perfConn != null) { perfConn.close(); } } } } /** * Tests fix for BUG#13374 - ResultSet.getStatement() on closed result set * returns NULL (as per JDBC 4.0 spec, but not backwards-compatible). * * @throws Exception * if the test fails */ public void testBug13374() throws Exception { Statement retainStmt = null; Connection retainConn = null; try { Properties props = new Properties(); props.setProperty("retainStatementAfterResultSetClose", "true"); retainConn = getConnectionWithProps(props); retainStmt = retainConn.createStatement(); this.rs = retainStmt.executeQuery("SELECT 1"); this.rs.close(); assertNotNull(this.rs.getStatement()); this.rs = this.stmt.executeQuery("SELECT 1"); this.rs.close(); try { this.rs.getStatement(); } catch (SQLException sqlEx) { assertEquals(sqlEx.getSQLState(), SQLError.SQL_STATE_GENERAL_ERROR); } } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } if (retainStmt != null) { retainStmt.close(); } if (retainConn != null) { retainConn.close(); } } } /** * Tests bugfix for BUG#14562 - metadata/type for MEDIUMINT UNSIGNED is * incorrect. * * @throws Exception * if the test fails. */ public void testBug14562() throws Exception { createTable("testBug14562", "(row_order INT, signed_field MEDIUMINT, unsigned_field MEDIUMINT UNSIGNED)"); try { this.stmt .executeUpdate("INSERT INTO testBug14562 VALUES (1, -8388608, 0), (2, 8388607, 16777215)"); this.rs = this.stmt .executeQuery("SELECT signed_field, unsigned_field FROM testBug14562 ORDER BY row_order"); traverseResultSetBug14562(); this.rs = this.conn .prepareStatement( "SELECT signed_field, unsigned_field FROM testBug14562 ORDER BY row_order") .executeQuery(); traverseResultSetBug14562(); if (versionMeetsMinimum(5, 0)) { CallableStatement storedProc = null; try { this.stmt .executeUpdate("DROP PROCEDURE IF EXISTS sp_testBug14562"); this.stmt .executeUpdate("CREATE PROCEDURE sp_testBug14562() BEGIN SELECT signed_field, unsigned_field FROM testBug14562 ORDER BY row_order; END"); storedProc = this.conn .prepareCall("{call sp_testBug14562()}"); storedProc.execute(); this.rs = storedProc.getResultSet(); traverseResultSetBug14562(); this.stmt .executeUpdate("DROP PROCEDURE IF EXISTS sp_testBug14562_1"); this.stmt .executeUpdate("CREATE PROCEDURE sp_testBug14562_1(OUT param_1 MEDIUMINT, OUT param_2 MEDIUMINT UNSIGNED) BEGIN SELECT signed_field, unsigned_field INTO param_1, param_2 FROM testBug14562 WHERE row_order=1; END"); storedProc = this.conn .prepareCall("{call sp_testBug14562_1(?, ?)}"); storedProc.registerOutParameter(1, Types.INTEGER); storedProc.registerOutParameter(2, Types.INTEGER); storedProc.execute(); assertEquals("java.lang.Integer", storedProc.getObject(1) .getClass().getName()); assertEquals("java.lang.Integer", storedProc.getObject(2) .getClass().getName()); } finally { if (storedProc != null) { storedProc.close(); } this.stmt .executeUpdate("DROP PROCEDURE IF EXISTS sp_testBug14562"); } } this.rs = this.conn.getMetaData().getColumns( this.conn.getCatalog(), null, "testBug14562", "%field"); assertTrue(this.rs.next()); assertEquals(Types.INTEGER, this.rs.getInt("DATA_TYPE")); assertEquals("MEDIUMINT", this.rs.getString("TYPE_NAME") .toUpperCase(Locale.US)); assertTrue(this.rs.next()); assertEquals(Types.INTEGER, this.rs.getInt("DATA_TYPE")); assertEquals("MEDIUMINT UNSIGNED", this.rs.getString("TYPE_NAME") .toUpperCase(Locale.US)); // // The following test is harmless in the 3.1 driver, but // is needed for the 5.0 driver, so we'll leave it here // if (versionMeetsMinimum(5, 0, 14)) { Connection infoSchemConn = null; try { Properties props = new Properties(); props.setProperty("useInformationSchema", "true"); infoSchemConn = getConnectionWithProps(props); this.rs = infoSchemConn.getMetaData().getColumns( infoSchemConn.getCatalog(), null, "testBug14562", "%field"); assertTrue(this.rs.next()); asse
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -