?? metadataregressiontest.java
字號:
props.setProperty("characterEncoding", "Big5"); big5Conn = getConnectionWithProps(props); big5Stmt = big5Conn.createStatement(); byte[] foobar = testString.getBytes("Big5"); System.out.println(foobar); this.rs = big5Stmt.executeQuery("select 1 as '\u5957 \u9910'"); String retrString = this.rs.getMetaData().getColumnName(1); assertTrue(testString.equals(retrString)); big5PrepStmt = big5Conn .prepareStatement("select 1 as '\u5957 \u9910'"); this.rs = big5PrepStmt.executeQuery(); retrString = this.rs.getMetaData().getColumnName(1); assertTrue(testString.equals(retrString)); } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } if (big5Stmt != null) { big5Stmt.close(); } if (big5PrepStmt != null) { big5PrepStmt.close(); } if (big5Conn != null) { big5Conn.close(); } } } } /** * Tests fix for Bug#8812, DBMD.getIndexInfo() returning inverted values for * 'NON_UNIQUE' column. * * @throws Exception * if the test fails. */ public void testBug8812() throws Exception { String tableName = "testBug8812"; try { createTable(tableName, "(field1 INT, field2 INT, INDEX(field1), UNIQUE INDEX(field2))"); DatabaseMetaData dbmd = this.conn.getMetaData(); this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, tableName, true, false); assertTrue(this.rs.next()); // there should be one row that meets // this requirement assertEquals(this.rs.getBoolean("NON_UNIQUE"), false); this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, tableName, false, false); assertTrue(this.rs.next()); // there should be two rows that meets // this requirement assertEquals(this.rs.getBoolean("NON_UNIQUE"), false); assertTrue(this.rs.next()); assertEquals(this.rs.getBoolean("NON_UNIQUE"), true); } finally { dropTable(tableName); } } /** * Tests fix for BUG#8800 - supportsMixedCase*Identifiers() returns wrong * value on servers running on case-sensitive filesystems. */ public void testBug8800() throws Exception { assertEquals(((com.mysql.jdbc.Connection) this.conn) .lowerCaseTableNames(), !this.conn.getMetaData() .supportsMixedCaseIdentifiers()); assertEquals(((com.mysql.jdbc.Connection) this.conn) .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(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";
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -