?? metadataregressiontest.java
字號:
} } finally { closeMemberJDBCResources(); } } private void checkMetadataForBug22613(Connection c) throws Exception { String maxValue = "a,bc,def,ghij"; try { DatabaseMetaData meta = c.getMetaData(); this.rs = meta.getColumns(null, this.conn.getCatalog(), "bug22613", "s"); this.rs.first(); assertEquals(maxValue.length(), rs.getInt("COLUMN_SIZE")); this.rs = meta.getColumns(null, c.getCatalog(), "bug22613", "t"); this.rs.first(); assertEquals(4, rs.getInt("COLUMN_SIZE")); } finally { closeMemberJDBCResources(); } } /** * Fix for BUG#22628 - Driver.getPropertyInfo() throws NullPointerException for URL that only specifies * host and/or port. * * @throws Exception if the test fails. */ public void testBug22628() throws Exception { DriverPropertyInfo[] dpi = new NonRegisteringDriver().getPropertyInfo("jdbc:mysql://bogus:9999", new Properties()); boolean foundHost = false; for (int i = 0; i < dpi.length; i++) { if ("bogus:9999".equals(dpi[i].value)) { foundHost = true; break; } } assertTrue(foundHost); } 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(); } } } public void testRSMDToStringFromDBMD() throws Exception { try { this.rs = this.conn.getMetaData().getTypeInfo(); this.rs.getMetaData().toString(); // used to cause NPE } finally { closeMemberJDBCResources(); } } public void testCharacterSetForDBMD() throws Exception { if (versionMeetsMinimum(4, 0)) { // server is broken, fixed in 5.2/6.0? if (!versionMeetsMinimum(5, 2)) { return; } } String quoteChar = this.conn.getMetaData().getIdentifierQuoteString(); String tableName = quoteChar + "\u00e9\u0074\u00e9" + quoteChar; createTable(tableName, "(field1 int)"); this.rs = this.conn.getMetaData().getTables(this.conn.getCatalog(), null, tableName, new String[] {"TABLE"}); assertEquals(true, this.rs.next()); System.out.println(this.rs.getString("TABLE_NAME")); System.out.println(new String(this.rs.getBytes("TABLE_NAME"), "UTF-8")); } /** * Tests fix for BUG#18258 - Nonexistent catalog/database causes SQLException * to be raised, rather than returning empty result set. * * @throws Exception if the test fails. */ public void testBug18258() throws Exception { String bogusDatabaseName = "abcdefghijklmnopqrstuvwxyz"; this.conn.getMetaData().getTables(bogusDatabaseName, "%", "%", new String[] {"TABLE", "VIEW"}); this.conn.getMetaData().getColumns(bogusDatabaseName, "%", "%", "%"); this.conn.getMetaData().getProcedures(bogusDatabaseName, "%", "%"); } /** * Tests fix for BUG#23303 - DBMD.getSchemas() doesn't return a TABLE_CATALOG column. * * @throws Exception if the test fails. */ public void testBug23303() throws Exception { try { this.rs = this.conn.getMetaData().getSchemas(); this.rs.findColumn("TABLE_CATALOG"); } finally { closeMemberJDBCResources(); } } /** * Tests fix for BUG#23304 - DBMD using "show" and DBMD using * information_schema do not return results consistent with eachother. * * (note this fix only addresses the inconsistencies, not the issue that * the driver is treating schemas differently than some users expect. * * We will revisit this behavior when there is full support for schemas * in MySQL). * * @throws Exception */ public void testBug23304() throws Exception { if (!versionMeetsMinimum(5, 0)) { return; } Connection connShow = null; Connection connInfoSchema = null; ResultSet rsShow = null; ResultSet rsInfoSchema = null; try { Properties noInfoSchemaProps = new Properties(); noInfoSchemaProps.setProperty("useInformationSchema", "false"); Properties infoSchemaProps = new Properties(); infoSchemaProps.setProperty("useInformationSchema", "true"); infoSchemaProps.setProperty("dumpQueriesOnException", "true"); connShow = getConnectionWithProps(noInfoSchemaProps); connInfoSchema = getConnectionWithProps(infoSchemaProps); DatabaseMetaData dbmdUsingShow = connShow.getMetaData(); DatabaseMetaData dbmdUsingInfoSchema = connInfoSchema.getMetaData(); assertNotSame(dbmdUsingShow.getClass(), dbmdUsingInfoSchema.getClass()); if (!isRunningOnJdk131()) { rsShow = dbmdUsingShow.getSchemas(); rsInfoSchema = dbmdUsingInfoSchema.getSchemas(); compareResultSets(rsShow, rsInfoSchema); } /* rsShow = dbmdUsingShow.getTables(connShow.getCatalog(), null, "%", new String[] {"TABLE", "VIEW"}); rsInfoSchema = dbmdUsingInfoSchema.getTables(connInfoSchema.getCatalog(), null, "%", new String[] {"TABLE", "VIEW"}); compareResultSets(rsShow, rsInfoSchema); rsShow = dbmdUsingShow.getTables(null, null, "%", new String[] {"TABLE", "VIEW"}); rsInfoSchema = dbmdUsingInfoSchema.getTables(null, null, "%", new String[] {"TABLE", "VIEW"}); compareResultSets(rsShow, rsInfoSchema); */ createTable("t_testBug23304", "(field1 int primary key not null, field2 tinyint, field3 mediumint, field4 mediumint, field5 bigint, field6 float, field7 double, field8 decimal, field9 char(32), field10 varchar(32), field11 blob, field12 mediumblob, field13 longblob, field14 text, field15 mediumtext, field16 longtext, field17 date, field18 time, field19 datetime, field20 timestamp)"); rsShow = dbmdUsingShow.getColumns(connShow.getCatalog(), null, "t_testBug23304", "%"); rsInfoSchema = dbmdUsingInfoSchema.getColumns(connInfoSchema.getCatalog(), null, "t_testBug23304", "%"); compareResultSets(rsShow, rsInfoSchema); } finally { if (rsShow != null) { rsShow.close(); } if (rsInfoSchema != null) { rsInfoSchema.close(); } } } private void compareResultSets(ResultSet expected, ResultSet actual) throws Exception { if (expected == null && actual != null) { fail("Expected null result set, actual was not null."); } else if (expected != null && actual == null) { fail("Expected non-null actual result set."); } else if (expected == null && actual == null) { return; } expected.last(); int expectedRows = expected.getRow(); actual.last(); int actualRows = actual.getRow(); assertEquals(expectedRows, actualRows); ResultSetMetaData metadataExpected = expected.getMetaData(); ResultSetMetaData metadataActual = actual.getMetaData(); assertEquals(metadataExpected.getColumnCount(), metadataActual.getColumnCount()); for (int i = 0; i < metadataExpected.getColumnCount(); i++) { assertEquals(metadataExpected.getColumnName(i + 1), metadataActual.getColumnName(i + 1)); assertEquals(metadataExpected.getColumnType(i + 1), metadataActual.getColumnType(i + 1)); assertEquals(metadataExpected.getColumnClassName(i + 1), metadataActual.getColumnClassName(i + 1)); } expected.beforeFirst(); actual.beforeFirst(); StringBuffer messageBuf = null; while (expected.next() && actual.next()) { if (messageBuf != null) { messageBuf.append("\n"); } for (int i = 0; i < metadataExpected.getColumnCount(); i++) { if (expected.getObject(i + 1) == null && actual.getObject(i + 1) == null) { continue; } if ((expected.getObject(i + 1) == null && actual.getObject(i + 1) != null) || (expected.getObject(i + 1) != null && actual.getObject(i + 1) == null) || (!expected.getObject(i + 1).equals(actual.getObject(i + 1)))) { if ("COLUMN_DEF".equals(metadataExpected.getColumnName(i + 1)) && (expected.getObject(i + 1) == null && actual.getString(i + 1).length() == 0) || (expected.getString(i + 1).length() == 0 && actual.getObject(i + 1) == null)) { continue; // known bug with SHOW FULL COLUMNS, and we can't distinguish between null and '' // for a default } if (messageBuf == null) { messageBuf = new StringBuffer(); } else { messageBuf.append("\n"); } messageBuf.append("On row " + expected.getRow() + " ,for column named " + metadataExpected.getColumnName(i + 1) + ", expected '" + expected.getObject(i + 1) + "', found '" + actual.getObject(i + 1) + "'"); } } } if (messageBuf != null) { fail(messageBuf.toString()); } } /** * Tests fix for BUG#25624 - Whitespace surrounding storage/size specifiers in stored procedure * declaration causes NumberFormatException to be thrown when calling stored procedure. * * @throws Exception */ public void testBug25624() throws Exception { if (!versionMeetsMinimum(5, 0)) { return; } // // we changed up the parameters to get coverage of the fixes, // also note that whitespace _is_ significant in the DDL... // createProcedure( "testBug25624", "(in _par1 decimal( 10 , 2 ) , in _par2 varchar( 4 )) BEGIN select 1; END"); this.conn.prepareCall("{call testBug25624(?,?)}").close(); } /** * Tests fix for BUG#27867 - Schema objects with identifiers other than * the connection character aren't retrieved correctly in ResultSetMetadata. * * @throws Exception if the test fails. */ public void testBug27867() throws Exception { try { String gbkColumnName = "\u00e4\u00b8\u00ad\u00e6\u2013\u2021\u00e6\u00b5\u2039\u00e8\u00af\u2022"; createTable("ColumnNameEncoding", "(" + "`" + gbkColumnName + "` varchar(1) default NULL," + "`ASCIIColumn` varchar(1) default NULL" + ")ENGINE=MyISAM DEFAULT CHARSET=utf8"); this.rs = this.stmt .executeQuery("SELECT * FROM ColumnNameEncoding"); java.sql.ResultSetMetaData tblMD = this.rs.getMetaData(); assertEquals(gbkColumnName, tblMD.getColumnName(1)); assertEquals("ASCIIColumn", tblMD.getColumnName(2)); } finally { closeMemberJDBCResources(); } } /** * Fixed BUG#27915 - DatabaseMetaData.getColumns() doesn't * contain SCOPE_* or IS_AUTOINCREMENT columns. * * @throws Exception */ public void testBug27915() throws Exception { createTable("testBug27915", "(field1 int not null primary key auto_increment, field2 int)"); DatabaseMetaData dbmd = this.conn.getMetaData(); try { this.rs = dbmd.getColumns(this.conn.getCatalog(), null, "testBug27915", "%"); this.rs.next(); checkBug27915(); if (versionMeetsMinimum(5, 0)) { this.rs = getConnectionWithProps("useInformationSchema=true") .getMetaData().getColumns(this.conn.getCatalog(), null, "testBug27915", "%"); this.rs.next(); checkBug27915(); } } finally { closeMemberJDBCResources(); } } private void checkBug27915() throws SQLException { assertNull(this.rs.getString("SCOPE_CATALOG")); assertNull(this.rs.getString("SCOPE_SCHEMA")); assertNull(this.rs.getString("SCOPE_TABLE")); assertNull(this.rs.getString("SOURCE_DATA_TYPE")); assertEquals("YES", this.rs.getString("IS_AUTOINCREMENT")); this.rs.next(); assertNull(this.rs.getString("SCOPE_CATALOG")); assertNull(this.rs.getString("SCOPE_SCHEMA")); assertNull(this.rs.getString("SCOPE_TABLE")); assertNull(this.rs.getString("SOURCE_DATA_TYPE")); assertEquals("NO", this.rs.getString("IS_AUTOINCREMENT")); } /** * Tests fix for BUG#27916 - UNSIGNED types not reported * via DBMD.getTypeInfo(), and capitalization of types is * not consistent between DBMD.getColumns(), RSMD.getColumnTypeName() * and DBMD.getTypeInfo(). * * This fix also ensures that the precision of UNSIGNED MEDIUMINT * and UNSIGNED BIGINT is reported correctly via DBMD.getColumns(). * * @throws Exception */ public void testBug27916() throws Exception { createTable( "testBug27916", "(field1 TINYINT UNSIGNED, field2 SMALLINT UNSIGNED, field3 INT UNSIGNED, field4 INTEGER UNSIGNED, field5 MEDIUMINT UNSIGNED, field6 BIGINT UNSIGNED)"); ResultSetMetaData rsmd = this.stmt.executeQuery( "SELECT * FROM testBug27916").getMetaData(); HashMap typeNameToPrecision = new HashMap(); this.rs = this.conn.getMetaData().getTypeInfo(); while (this.rs.next()) { typeNameToPrecision.put(this.rs.getString("TYPE_NAME"), this.rs .getObject("PRECISION")); } this.rs = this.conn.getMetaData().getColumns(this.conn.getCatalog(), null, "testBug27916", "%"); for (int i = 0; i < rsmd.getColumnCount(); i++) { this.rs.next(); String typeName = this.rs.getString("TYPE_NAME"); assertEquals(typeName, rsmd.getColumnTypeName(i + 1)); assertEquals(typeName, this.rs.getInt("COLUMN_SIZE"), rsmd .getPrecision(i + 1)); assertEquals(typeName, new Integer(rsmd.getPrecision(i + 1)), typeNameToPrecision.get(typeName)); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -