📄 metadataregressiontest.java
字号:
.lowerCaseTableNames(), !this.conn.getMetaData() .supportsMixedCaseQuotedIdentifiers()); } /** * Tests fix for BUG#8792 - DBMD.supportsResultSetConcurrency() not * returning true for forward-only/read-only result sets (we obviously * support this). * * @throws Exception * if the test fails. */ public void testBug8792() throws Exception { DatabaseMetaData dbmd = this.conn.getMetaData(); assertTrue(dbmd.supportsResultSetConcurrency( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)); assertTrue(dbmd.supportsResultSetConcurrency( ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)); assertTrue(dbmd.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)); assertTrue(dbmd.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)); assertTrue(!dbmd.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)); assertTrue(!dbmd.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)); // Check error conditions try { dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, Integer.MIN_VALUE); fail("Exception should've been raised for bogus concurrency value"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT.equals(sqlEx .getSQLState())); } try { assertTrue(dbmd.supportsResultSetConcurrency( ResultSet.TYPE_SCROLL_INSENSITIVE, Integer.MIN_VALUE)); fail("Exception should've been raised for bogus concurrency value"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT.equals(sqlEx .getSQLState())); } try { assertTrue(dbmd.supportsResultSetConcurrency(Integer.MIN_VALUE, Integer.MIN_VALUE)); fail("Exception should've been raised for bogus concurrency value"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_ILLEGAL_ARGUMENT.equals(sqlEx .getSQLState())); } } /** * Tests fix for BUG#8803, 'DATA_TYPE' column from * DBMD.getBestRowIdentifier() causes ArrayIndexOutOfBoundsException when * accessed (and in fact, didn't return any value). * * @throws Exception * if the test fails. */ public void testBug8803() throws Exception { String tableName = "testBug8803"; createTable(tableName, "(field1 INT NOT NULL PRIMARY KEY)"); DatabaseMetaData metadata = this.conn.getMetaData(); try { this.rs = metadata.getBestRowIdentifier(this.conn.getCatalog(), null, tableName, DatabaseMetaData.bestRowNotPseudo, true); assertTrue(this.rs.next()); this.rs.getInt("DATA_TYPE"); // **** Fails here ***** } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests fix for BUG#9320 - PreparedStatement.getMetaData() inserts blank * row in database under certain conditions when not using server-side * prepared statements. * * @throws Exception * if the test fails. */ public void testBug9320() throws Exception { createTable("testBug9320", "(field1 int)"); testAbsenceOfMetadataForQuery("INSERT INTO testBug9320 VALUES (?)"); testAbsenceOfMetadataForQuery("UPDATE testBug9320 SET field1=?"); testAbsenceOfMetadataForQuery("DELETE FROM testBug9320 WHERE field1=?"); } /** * Tests fix for BUG#9778, DBMD.getTables() shouldn't return tables if views * are asked for, even if the database version doesn't support views. * * @throws Exception * if the test fails. */ public void testBug9778() throws Exception { String tableName = "testBug9778"; try { createTable(tableName, "(field1 int)"); this.rs = this.conn.getMetaData().getTables(null, null, tableName, new String[] { "VIEW" }); assertEquals(false, this.rs.next()); this.rs = this.conn.getMetaData().getTables(null, null, tableName, new String[] { "TABLE" }); assertEquals(true, this.rs.next()); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests fix for BUG#9769 - Should accept null for procedureNamePattern, * even though it isn't JDBC compliant, for legacy's sake. * * @throws Exception * if the test fails. */ public void testBug9769() throws Exception { boolean defaultPatternConfig = ((com.mysql.jdbc.Connection) this.conn) .getNullNamePatternMatchesAll(); // We're going to change this in 3.2.x, so make that test here, so we // catch it. if (this.conn.getMetaData().getDriverMajorVersion() == 3 && this.conn.getMetaData().getDriverMinorVersion() >= 2) { assertEquals(false, defaultPatternConfig); } else { assertEquals(true, defaultPatternConfig); } try { this.conn.getMetaData().getProcedures(this.conn.getCatalog(), "%", null); if (!defaultPatternConfig) { // we shouldn't have gotten here fail("Exception should've been thrown"); } } catch (SQLException sqlEx) { if (!defaultPatternConfig) { assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx .getSQLState()); } else { throw sqlEx; // we shouldn't have gotten an exception here } } // FIXME: TO test for 3.1.9 // getColumns(); // getTablePrivileges(); // getTables(); } /** * Tests fix for BUG#9917 - Should accept null for catalog in DBMD methods, * even though it's not JDBC-compliant for legacy's sake. * * @throws Exception * if the test fails. */ public void testBug9917() throws Exception { String tableName = "testBug9917"; boolean defaultCatalogConfig = ((com.mysql.jdbc.Connection) this.conn) .getNullCatalogMeansCurrent(); // We're going to change this in 3.2.x, so make that test here, so we // catch it. if (this.conn.getMetaData().getDriverMajorVersion() == 3 && this.conn.getMetaData().getDriverMinorVersion() >= 2) { assertEquals(false, defaultCatalogConfig); } else { assertEquals(true, defaultCatalogConfig); } try { createTable(tableName, "(field1 int)"); String currentCatalog = this.conn.getCatalog(); try { this.rs = this.conn.getMetaData().getTables(null, null, tableName, new String[] { "TABLE" }); if (!defaultCatalogConfig) { // we shouldn't have gotten here fail("Exception should've been thrown"); } assertEquals(true, this.rs.next()); assertEquals(currentCatalog, this.rs.getString("TABLE_CAT")); // FIXME: Methods to test for 3.1.9 // // getBestRowIdentifier() // getColumns() // getCrossReference() // getExportedKeys() // getImportedKeys() // getIndexInfo() // getPrimaryKeys() // getProcedures() } catch (SQLException sqlEx) { if (!defaultCatalogConfig) { assertEquals(SQLError.SQL_STATE_ILLEGAL_ARGUMENT, sqlEx .getSQLState()); } else { throw sqlEx; // we shouldn't have gotten an exception // here } } } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests fix for BUG#11575 -- DBMD.storesLower/Mixed/UpperIdentifiers() * reports incorrect values for servers deployed on Windows. * * @throws Exception if the test fails. */ public void testBug11575() throws Exception { DatabaseMetaData dbmd= this.conn.getMetaData(); if (isServerRunningOnWindows()) { assertEquals(true, dbmd.storesLowerCaseIdentifiers()); assertEquals(true, dbmd.storesLowerCaseQuotedIdentifiers()); assertEquals(false, dbmd.storesMixedCaseIdentifiers()); assertEquals(false, dbmd.storesMixedCaseQuotedIdentifiers()); assertEquals(false, dbmd.storesUpperCaseIdentifiers()); assertEquals(false, dbmd.storesUpperCaseQuotedIdentifiers()); } else { assertEquals(true, dbmd.storesLowerCaseIdentifiers()); assertEquals(true, dbmd.storesLowerCaseQuotedIdentifiers()); assertEquals(true, dbmd.storesMixedCaseIdentifiers()); assertEquals(true, dbmd.storesMixedCaseQuotedIdentifiers()); assertEquals(true, dbmd.storesUpperCaseIdentifiers()); assertEquals(true, dbmd.storesUpperCaseQuotedIdentifiers()); } } /** * Tests fix for BUG#11781, foreign key information * that is quoted is parsed incorrectly. */ public void testBug11781() throws Exception { createTable("`app tab`", "( C1 int(11) NULL, INDEX NEWINX (C1), INDEX NEWINX2 (C1)) ENGINE = InnoDB CHECKSUM = 0 COMMENT = 'InnoDB free: 3072 kB; (`C1`) REFER`test/app tab`(`C1`)' PACK_KEYS = 0"); this.stmt.executeUpdate("ALTER TABLE `app tab` ADD CONSTRAINT APPFK FOREIGN KEY (C1) REFERENCES `app tab` (C1)"); /* this.rs = this.conn.getMetaData().getCrossReference( this.conn.getCatalog(), null, "app tab", this.conn.getCatalog(), null, "app tab"); */ rs = ((com.mysql.jdbc.DatabaseMetaData)this.conn.getMetaData()).extractForeignKeyFromCreateTable(this.conn.getCatalog(),"app tab"); assertTrue("must return a row",rs.next()) ; assertEquals("comment; APPFK(`C1`) REFER `test`/ `app tab` (`C1`)", rs.getString(3)); rs.close(); rs = this.conn.getMetaData().getImportedKeys(this.conn.getCatalog(), null, "app tab"); assertTrue(this.rs.next()); rs = this.conn.getMetaData().getExportedKeys(this.conn.getCatalog(), null, "app tab"); assertTrue(this.rs.next()); } /** * Tests fix for BUG#12970 - java.sql.Types.OTHER returned for * binary and varbinary columns. * */ public void testBug12970() throws Exception { if (versionMeetsMinimum(5, 0, 8)) { String tableName = "testBug12970"; createTable(tableName, "(binary_field BINARY(32), varbinary_field VARBINARY(64))"); try { this.rs = this.conn.getMetaData().getColumns(this.conn.getCatalog(), null, tableName, "%"); assertTrue(this.rs.next()); assertEquals(Types.BINARY, this.rs.getInt("DATA_TYPE")); assertEquals(32, this.rs.getInt("COLUMN_SIZE")); assertTrue(this.rs.next()); assertEquals(Types.VARBINARY, this.rs.getInt("DATA_TYPE")); assertEquals(64, this.rs.getInt("COLUMN_SIZE")); this.rs.close(); this.rs = this.stmt.executeQuery("SELECT binary_field, varbinary_field FROM " + tableName); ResultSetMetaData rsmd = this.rs.getMetaData(); assertEquals(Types.BINARY, rsmd.getColumnType(1)); assertEquals(32, rsmd.getPrecision(1)); assertEquals(Types.VARBINARY, rsmd.getColumnType(2)); assertEquals(64, rsmd.getPrecision(2)); this.rs.close(); } finally { if (this.rs != null) { this.rs.close(); } } } } /** * Tests fix for BUG#13277 - RSMD for generated keys * has NPEs when a connection is referenced. * * @throws Exception */ public void testBug13277() throws Exception { createTable("testBug13277", "(field1 INT NOT NULL PRIMARY KEY AUTO_INCREMENT, field2 VARCHAR(32))"); try { this.stmt.executeUpdate("INSERT INTO testBug13277 (field2) VALUES ('abcdefg')", Statement.RETURN_GENERATED_KEYS); this.rs = this.stmt.getGeneratedKeys(); ResultSetMetaData rsmd = this.rs.getMetaData(); checkRsmdForBug13277(rsmd); this.rs.close(); for (int i = 0; i < 5; i++) { this.stmt.addBatch("INSERT INTO testBug13277 (field2) VALUES ('abcdefg')"); } this.stmt.executeBatch(); this.rs = this.stmt.getGeneratedKeys(); rsmd = this.rs.getMetaData(); checkRsmdForBug13277(rsmd); this.rs.close(); this.pstmt = this.conn.prepareStatement( "INSERT INTO testBug13277 (field2) VALUES ('abcdefg')", Statement.RETURN_GENERATED_KEYS); this.pstmt.executeUpdate(); this.rs = this.pstmt.getGeneratedKeys(); rsmd = this.rs.getMetaData(); checkRsmdForBug13277(rsmd); this.rs.close(); this.pstmt.addBatch(); this.pstmt.addBatch(); this.pstmt.executeUpdate(); this.rs = this.pstmt.getGeneratedKeys(); rsmd = this.rs.getMetaData(); checkRsmdForBug13277(rsmd); this.rs.close(); } finally { if (this.pstmt != null) { this.pstmt.close(); this.pstmt = null; } if (this.rs != null) { this.rs.close(); this.rs = null; } } } private void checkRsmdForBug13277(ResultSetMetaData rsmd) throws SQLException { assertEquals(17, rsmd.getColumnDisplaySize(1)); assertEquals(false, rsmd.isDefinitelyWritable(1)); assertEquals(true, rsmd.isReadOnly(1)); assertEquals(false, rsmd.isWritable(1)); } public void testSupportsCorrelatedSubqueries() throws Exception { DatabaseMetaData dbmd = this.conn.getMetaData(); assertEquals(versionMeetsMinimum(4, 1), dbmd.supportsCorrelatedSubqueries()); } public void testSupportesGroupByUnrelated() throws Exception { DatabaseMetaData dbmd = this.conn.getMetaData(); assertEquals(true, dbmd.supportsGroupByUnrelated()); } private void testAbsenceOfMetadataForQuery(String query) throws Exception { try { this.pstmt = this.conn.prepareStatement(query); ResultSetMetaData rsmd = this.pstmt.getMetaData(); assertNull(rsmd); this.pstmt = ((com.mysql.jdbc.Connection) this.conn) .clientPrepareStatement(query); rsmd = this.pstmt.getMetaData(); assertNull(rsmd); } finally { if (this.pstmt != null) { this.pstmt.close(); } } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -