⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 metadataregressiontest.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			}		}	}	/**	 * Tests fix for BUG#16277 - Invalid classname returned for	 * RSMD.getColumnClassName() for BIGINT type.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug16277() throws Exception {		createTable("testBug16277", "(field1 BIGINT, field2 BIGINT UNSIGNED)");		ResultSetMetaData rsmd = this.stmt.executeQuery(				"SELECT field1, field2 FROM testBug16277").getMetaData();		assertEquals("java.lang.Long", rsmd.getColumnClassName(1));		assertEquals("java.math.BigInteger", rsmd.getColumnClassName(2));	}	/**	 * Tests fix for BUG#18554 - Aliased column names where length of name > 251	 * are corrupted.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug18554() throws Exception {		testBug18554(249);		testBug18554(250);		testBug18554(251);		testBug18554(252);		testBug18554(253);		testBug18554(254);		testBug18554(255);	}	private void testBug18554(int columnNameLength) throws Exception {		StringBuffer buf = new StringBuffer(columnNameLength + 2);		for (int i = 0; i < columnNameLength; i++) {			buf.append((char) ((Math.random() * 26) + 65));		}		String colName = buf.toString();		this.rs = this.stmt.executeQuery("select curtime() as `" + colName				+ "`");		ResultSetMetaData meta = this.rs.getMetaData();		assertEquals(colName, meta.getColumnLabel(1));	}	private void checkRsmdForBug13277(ResultSetMetaData rsmd)			throws SQLException {		assertEquals(17, rsmd.getColumnDisplaySize(1));		if (versionMeetsMinimum(4, 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());	}		/**	 * Tests fix for BUG#21267, ParameterMetaData throws NullPointerException	 * when prepared SQL actually has a syntax error	 * 	 * @throws Exception	 */	public void testBug21267() throws Exception {		if (isRunningOnJdk131()) {			return; // no parameter metadata on JDK-1.3.1		}				createTable(				"bug21267",				"(`Col1` int(11) NOT NULL,`Col2` varchar(45) default NULL,`Col3` varchar(45) default NULL,PRIMARY KEY  (`Col1`))");		try {			this.pstmt = this.conn					.prepareStatement("SELECT Col1, Col2,Col4 FROM bug21267 WHERE Col1=?");			this.pstmt.setInt(1, 1);			java.sql.ParameterMetaData psMeta = this.pstmt					.getParameterMetaData();			try {				assertEquals(0, psMeta.getParameterType(1));			} catch (SQLException sqlEx) {				assertEquals(SQLError.SQL_STATE_DRIVER_NOT_CAPABLE, sqlEx.getSQLState());			}						this.pstmt.close();						Properties props = new Properties();			props.setProperty("generateSimpleParameterMetadata", "true");						this.pstmt = getConnectionWithProps(props).prepareStatement("SELECT Col1, Col2,Col4 FROM bug21267 WHERE Col1=?");						psMeta = this.pstmt.getParameterMetaData();						assertEquals(Types.VARCHAR, psMeta.getParameterType(1));		} finally {			closeMemberJDBCResources();		}	}	/**	 * Tests fix for BUG#21544 - When using information_schema for metadata, 	 * COLUMN_SIZE for getColumns() is not clamped to range of 	 * java.lang.Integer as is the case when not using 	 * information_schema, thus leading to a truncation exception that 	 * isn't present when not using information_schema.	 * 	 * @throws Exception if the test fails	 */	public void testBug21544() throws Exception {		if (!versionMeetsMinimum(5, 0)) {			return;		}				createTable("testBug21544",                "(foo_id INT NOT NULL, stuff LONGTEXT"                + ", PRIMARY KEY (foo_id)) TYPE=INNODB");				Connection infoSchemConn = null;				Properties props = new Properties();		props.setProperty("useInformationSchema", "true");		props.setProperty("jdbcCompliantTruncation", "false");				infoSchemConn = getConnectionWithProps(props);				try {	        this.rs = infoSchemConn.getMetaData().getColumns(null, null, 	        		"testBug21544",	                null);	        	        while (rs.next()) {	        	rs.getInt("COLUMN_SIZE");   	        }	    } finally {            if (infoSchemConn != null) {            	infoSchemConn.close();            }                        closeMemberJDBCResources();        }	}	/** 	 * Tests fix for BUG#22613 - DBMD.getColumns() does not return expected	 * COLUMN_SIZE for the SET type (fixed to be consistent with the ODBC driver)	 * 	 * @throws Exception if the test fails	 */	public void testBug22613() throws Exception {				createTable("bug22613", "( s set('a','bc','def','ghij') default NULL, t enum('a', 'ab', 'cdef'))");		try {			checkMetadataForBug22613(this.conn);						if (versionMeetsMinimum(5, 0)) {				Connection infoSchemConn = null;							try {					Properties props = new Properties();					props.setProperty("useInformationSchema", "true");										infoSchemConn = getConnectionWithProps(props);										checkMetadataForBug22613(infoSchemConn);				} finally {					if (infoSchemConn != null) {						infoSchemConn.close();					}				}			}		} 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();	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -