📄 metadataregressiontest.java
字号:
* 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(true, dbmd.storesUpperCaseQuotedIdentifiers()); } else { assertEquals(false, dbmd.storesLowerCaseIdentifiers()); assertEquals(false, dbmd.storesLowerCaseQuotedIdentifiers()); assertEquals(true, dbmd.storesMixedCaseIdentifiers()); assertEquals(true, dbmd.storesMixedCaseQuotedIdentifiers()); assertEquals(false, 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 { if (versionMeetsMinimum(5, 1)) { if (!versionMeetsMinimum(5, 2)) { // server bug prevents this test from functioning return; } } 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"); */ this.rs = ((com.mysql.jdbc.DatabaseMetaData) this.conn.getMetaData()) .extractForeignKeyFromCreateTable(this.conn.getCatalog(), "app tab"); assertTrue("must return a row", this.rs.next()); String catalog = this.conn.getCatalog(); assertEquals("comment; APPFK(`C1`) REFER `" + catalog + "`/ `app tab` (`C1`)", this.rs.getString(3)); this.rs.close(); this.rs = this.conn.getMetaData().getImportedKeys( this.conn.getCatalog(), null, "app tab"); assertTrue(this.rs.next()); this.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#12975 - OpenOffice expects DBMD.supportsIEF() to return * "true" if foreign keys are supported by the datasource, even though this * method also covers support for check constraints, which MySQL _doesn't_ * have. * * @throws Exception * if the test fails. */ public void testBug12975() throws Exception { assertEquals(false, this.conn.getMetaData() .supportsIntegrityEnhancementFacility()); Connection overrideConn = null; try { Properties props = new Properties(); props.setProperty("overrideSupportsIntegrityEnhancementFacility", "true"); overrideConn = getConnectionWithProps(props); assertEquals(true, overrideConn.getMetaData() .supportsIntegrityEnhancementFacility()); } finally { if (overrideConn != null) { overrideConn.close(); } } } /** * Tests fix for BUG#13277 - RSMD for generated keys has NPEs when a * connection is referenced. * * @throws Exception */ public void testBug13277() throws Exception { if (isRunningOnJdk131()) { return; // test not valid on JDK-1.3.1 } 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; } } } /** * Tests BUG13601 (which doesn't seem to be present in 3.1.11, but we'll * leave it in here for regression's-sake). * * @throws Exception * if the test fails. */ public void testBug13601() throws Exception { if (versionMeetsMinimum(5, 0)) { createTable("testBug13601", "(field1 BIGINT NOT NULL, field2 BIT default 0 NOT NULL) ENGINE=MyISAM"); this.rs = this.stmt .executeQuery("SELECT field1, field2 FROM testBug13601 WHERE 1=-1"); ResultSetMetaData rsmd = this.rs.getMetaData(); assertEquals(Types.BIT, rsmd.getColumnType(2)); assertEquals(Boolean.class.getName(), rsmd.getColumnClassName(2)); this.rs = this.conn.prepareStatement( "SELECT field1, field2 FROM testBug13601 WHERE 1=-1") .executeQuery(); rsmd = this.rs.getMetaData(); assertEquals(Types.BIT, rsmd.getColumnType(2)); assertEquals(Boolean.class.getName(), rsmd.getColumnClassName(2)); } } /** * Tests fix for BUG#14815 - DBMD.getColumns() doesn't return TABLE_NAME * correctly. * * @throws Exception * if the test fails */ public void testBug14815() throws Exception { try { createTable("testBug14815_1", "(field_1_1 int)"); createTable("testBug14815_2", "(field_2_1 int)"); boolean lcTableNames = this.conn.getMetaData() .storesLowerCaseIdentifiers(); String tableName1 = lcTableNames ? "testbug14815_1" : "testBug14815_1"; String tableName2 = lcTableNames ? "testbug14815_2" : "testBug14815_2"; this.rs = this.conn.getMetaData().getColumns( this.conn.getCatalog(), null, "testBug14815%", "%"); assertTrue(this.rs.next()); assertEquals(tableName1, this.rs.getString("TABLE_NAME")); assertEquals("field_1_1", this.rs.getString("COLUMN_NAME")); assertTrue(this.rs.next()); assertEquals(tableName2, this.rs.getString("TABLE_NAME")); assertEquals("field_2_1", this.rs.getString("COLUMN_NAME")); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests fix for BUG#15854 - DBMD.getColumns() returns wrong type for BIT. * * @throws Exception * if the test fails. */ public void testBug15854() throws Exception { if (versionMeetsMinimum(5, 0)) { createTable("testBug15854", "(field1 BIT)"); try { this.rs = this.conn.getMetaData().getColumns( this.conn.getCatalog(), null, "testBug15854", "field1"); assertTrue(this.rs.next()); assertEquals(Types.BIT, this.rs.getInt("DATA_TYPE")); } finally { if (this.rs != null) { ResultSet toClose = this.rs; this.rs = null; toClose.close(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -