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

📄 metadataregressiontest.java

📁 开发MySql数据库的最新JDBC驱动。
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
				assertTrue(rsmd.isCaseSensitive(2));				assertTrue(!rsmd.isCaseSensitive(3));				assertTrue(!rsmd.isCaseSensitive(4));				assertTrue(rsmd.isCaseSensitive(5));				assertTrue(rsmd.isCaseSensitive(6));				assertTrue(rsmd.isCaseSensitive(7));				assertTrue(rsmd.isCaseSensitive(8));				assertTrue(!rsmd.isCaseSensitive(9));				assertTrue(!rsmd.isCaseSensitive(10));				assertTrue(!rsmd.isCaseSensitive(11));				assertTrue(!rsmd.isCaseSensitive(12));			} finally {				this.stmt						.executeUpdate("DROP TABLE IF EXISTS testIsCaseSensitiveCs");			}		}	}	/**	 * Tests whether or not DatabaseMetaData.getColumns() returns the correct	 * java.sql.Types info.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testLongText() throws Exception {		try {			this.stmt.executeUpdate("DROP TABLE IF EXISTS testLongText");			this.stmt					.executeUpdate("CREATE TABLE testLongText (field1 LONGTEXT)");			this.rs = this.conn.getMetaData().getColumns(					this.conn.getCatalog(), null, "testLongText", "%");			assertTrue(this.rs.next());			assertTrue(this.rs.getInt("DATA_TYPE") == java.sql.Types.LONGVARCHAR);		} finally {			this.stmt.executeUpdate("DROP TABLE IF EXISTS testLongText");		}	}	/**	 * Tests for types being returned correctly	 * 	 * @throws Exception	 *             if an error occurs.	 */	public void testTypes() throws Exception {		try {			this.stmt.execute("DROP TABLE IF EXISTS typesRegressTest");			this.stmt.execute("CREATE TABLE typesRegressTest ("					+ "varcharField VARCHAR(32)," + "charField CHAR(2),"					+ "enumField ENUM('1','2'),"					+ "setField  SET('1','2','3')," + "tinyblobField TINYBLOB,"					+ "mediumBlobField MEDIUMBLOB," + "longblobField LONGBLOB,"					+ "blobField BLOB)");			this.rs = this.stmt.executeQuery("SELECT * from typesRegressTest");			ResultSetMetaData rsmd = this.rs.getMetaData();			int numCols = rsmd.getColumnCount();			for (int i = 0; i < numCols; i++) {				String columnName = rsmd.getColumnName(i + 1);				String columnTypeName = rsmd.getColumnTypeName(i + 1);				System.out.println(columnName + " -> " + columnTypeName);			}		} finally {			this.stmt.execute("DROP TABLE IF EXISTS typesRegressTest");		}	}	/**	 * Tests fix for BUG#4742, 'DOUBLE' mapped twice in getTypeInfo().	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug4742() throws Exception {		HashMap clashMap = new HashMap();		this.rs = this.conn.getMetaData().getTypeInfo();		while (this.rs.next()) {			String name = this.rs.getString(1);			assertTrue("Type represented twice in type info, '" + name + "'.",					!clashMap.containsKey(name));			clashMap.put(name, name);		}	}	/**	 * Tests fix for BUG#4138, getColumns() returns incorrect JDBC type for	 * unsigned columns.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug4138() throws Exception {		try {			String[] typesToTest = new String[] { "TINYINT", "SMALLINT",					"MEDIUMINT", "INTEGER", "BIGINT", "FLOAT", "DOUBLE",					"DECIMAL" };			short[] jdbcMapping = new short[] { Types.TINYINT, Types.SMALLINT,					Types.INTEGER, Types.INTEGER, Types.BIGINT, Types.REAL,					Types.DOUBLE, Types.DECIMAL };			this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4138");			StringBuffer createBuf = new StringBuffer();			createBuf.append("CREATE TABLE testBug4138 (");			boolean firstColumn = true;			for (int i = 0; i < typesToTest.length; i++) {				if (!firstColumn) {					createBuf.append(", ");				} else {					firstColumn = false;				}				createBuf.append("field");				createBuf.append((i + 1));				createBuf.append(" ");				createBuf.append(typesToTest[i]);				createBuf.append(" UNSIGNED");			}			createBuf.append(")");			this.stmt.executeUpdate(createBuf.toString());			DatabaseMetaData dbmd = this.conn.getMetaData();			this.rs = dbmd.getColumns(this.conn.getCatalog(), null,					"testBug4138", "field%");			assertTrue(this.rs.next());			for (int i = 0; i < typesToTest.length; i++) {				assertTrue(						"JDBC Data Type of "								+ this.rs.getShort("DATA_TYPE")								+ " for MySQL type '"								+ this.rs.getString("TYPE_NAME")								+ "' from 'DATA_TYPE' column does not match expected value of "								+ jdbcMapping[i] + ".",						jdbcMapping[i] == this.rs.getShort("DATA_TYPE"));				this.rs.next();			}			this.rs.close();			StringBuffer queryBuf = new StringBuffer("SELECT ");			firstColumn = true;			for (int i = 0; i < typesToTest.length; i++) {				if (!firstColumn) {					queryBuf.append(", ");				} else {					firstColumn = false;				}				queryBuf.append("field");				queryBuf.append((i + 1));			}			queryBuf.append(" FROM testBug4138");			this.rs = this.stmt.executeQuery(queryBuf.toString());			ResultSetMetaData rsmd = this.rs.getMetaData();			for (int i = 0; i < typesToTest.length; i++) {				assertTrue(jdbcMapping[i] == rsmd.getColumnType(i + 1));				String desiredTypeName = typesToTest[i] + " unsigned";				assertTrue(rsmd.getColumnTypeName((i + 1)) + " != "						+ desiredTypeName, desiredTypeName						.equalsIgnoreCase(rsmd.getColumnTypeName(i + 1)));			}		} finally {			this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4138");		}	}	/**	 * Here for housekeeping only, the test is actually in testBug4138().	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug4860() throws Exception {		testBug4138();	}	/**	 * Tests fix for BUG#4880 - RSMD.getPrecision() returns '0' for non-numeric	 * types.	 * 	 * Why-oh-why is this not in the spec, nor the api-docs, but in some	 * 'optional' book, _and_ it is a variance from both ODBC and the ANSI SQL	 * standard :p	 * 	 * (from the CTS testsuite)....	 * 	 * The getPrecision(int colindex) method returns an integer value	 * representing the number of decimal digits for number types,maximum length	 * in characters for character types,maximum length in bytes for JDBC binary	 * datatypes.	 * 	 * (See Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug4880() throws Exception {		try {			this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4880");			this.stmt					.executeUpdate("CREATE TABLE testBug4880 (field1 VARCHAR(80), field2 TINYBLOB, field3 BLOB, field4 MEDIUMBLOB, field5 LONGBLOB)");			this.rs = this.stmt					.executeQuery("SELECT field1, field2, field3, field4, field5 FROM testBug4880");			ResultSetMetaData rsmd = this.rs.getMetaData();			assertEquals(80, rsmd.getPrecision(1));			assertEquals(Types.VARCHAR, rsmd.getColumnType(1));			assertEquals(80, rsmd.getColumnDisplaySize(1));			assertEquals(255, rsmd.getPrecision(2));			assertEquals(Types.VARBINARY, rsmd.getColumnType(2));			assertTrue("TINYBLOB".equalsIgnoreCase(rsmd.getColumnTypeName(2)));			assertEquals(255, rsmd.getColumnDisplaySize(2));			assertEquals(65535, rsmd.getPrecision(3));			assertEquals(Types.LONGVARBINARY, rsmd.getColumnType(3));			assertTrue("BLOB".equalsIgnoreCase(rsmd.getColumnTypeName(3)));			assertEquals(65535, rsmd.getColumnDisplaySize(3));			assertEquals(16777215, rsmd.getPrecision(4));			assertEquals(Types.LONGVARBINARY, rsmd.getColumnType(4));			assertTrue("MEDIUMBLOB".equalsIgnoreCase(rsmd.getColumnTypeName(4)));			assertEquals(16777215, rsmd.getColumnDisplaySize(4));			if (versionMeetsMinimum(4, 1)) {				// Server doesn't send us enough information to detect LONGBLOB				// type				assertEquals(Integer.MAX_VALUE, rsmd.getPrecision(5));				assertEquals(Types.LONGVARBINARY, rsmd.getColumnType(5));				assertTrue("LONGBLOB".equalsIgnoreCase(rsmd						.getColumnTypeName(5)));				assertEquals(Integer.MAX_VALUE, rsmd.getColumnDisplaySize(5));			}		} finally {			this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4880");		}	}	/**	 * Tests fix for BUG#6399, ResultSetMetaData.getDisplaySize() is wrong for	 * multi-byte charsets.	 * 	 * @throws Exception	 *             if the test fails	 */	public void testBug6399() throws Exception {		if (versionMeetsMinimum(4, 1)) {			try {				this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug6399");				this.stmt						.executeUpdate("CREATE TABLE testBug6399 (field1 CHAR(3) CHARACTER SET UTF8, field2 CHAR(3) CHARACTER SET LATIN1, field3 CHAR(3) CHARACTER SET SJIS)");				this.stmt						.executeUpdate("INSERT INTO testBug6399 VALUES ('a', 'a', 'a')");				this.rs = this.stmt						.executeQuery("SELECT field1, field2, field3 FROM testBug6399");				ResultSetMetaData rsmd = this.rs.getMetaData();				assertTrue(3 == rsmd.getColumnDisplaySize(1));				assertTrue(3 == rsmd.getColumnDisplaySize(2));				assertTrue(3 == rsmd.getColumnDisplaySize(3));			} finally {				this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug6399");			}		}	}	/**	 * Tests fix for BUG#7081, DatabaseMetaData.getIndexInfo() ignoring 'unique'	 * parameters.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug7081() throws Exception {		String tableName = "testBug7081";		try {			createTable(tableName, "(field1 INT, INDEX(field1))");			DatabaseMetaData dbmd = this.conn.getMetaData();			this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null,					tableName, true, false);			assertTrue(!this.rs.next()); // there should be no rows that meet			// this requirement			this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null,					tableName, false, false);			assertTrue(this.rs.next()); // there should be one row that meets			// this requirement			assertTrue(!this.rs.next());		} finally {			dropTable(tableName);		}	}	/**	 * Tests fix for BUG#7033 - PreparedStatements don't encode Big5 (and other	 * multibyte) character sets correctly in static SQL strings.	 * 	 * @throws Exception	 *             if the test fails.	 */	public void testBug7033() throws Exception {		if (false) { // disabled for now			Connection big5Conn = null;			Statement big5Stmt = null;			PreparedStatement big5PrepStmt = null;			String testString = "\u5957 \u9910";			try {				Properties props = new Properties();				props.setProperty("useUnicode", "true");				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

⌨️ 快捷键说明

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