Description:
It appears that when the unique argument to
getIndexInfo is set to "true", that index of column
containing non-unique values is also returned. I need
to be able to determine programmatically, which
columns only allow unique values.
The exact method used is:
public ResultSet getIndexInfo(String catalog,
String schema,
String table,
boolean unique,
boolean approximate)
throws SQLException
The Sun JDBC API documentation says:
unique - when true, return only indices for unique
values; when false, return indices regardless of
whether unique or not
Is returning an index for a column with non-unique
values when unique is set to "true" the correct
behaviour or a bug?
Using version 4.0.18-nt of MySQL.
-George
How to repeat:
public void testNonUniqueBug() throws Exception {
try {
this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug");
this.stmt.executeUpdate("CREATE TABLE testNonUniqueBug(field1 INT, INDEX(field1))");
DatabaseMetaData dbmd = this.conn.getMetaData();
this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", true, false);
assertTrue(!this.rs.next()); // there should be no rows that meet this requirement
this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", false, false);
assertTrue(this.rs.next()); // there should be one row that meets this requirement
assertTrue(!this.rs.next());
} finally {
this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug");
}
}
Description: It appears that when the unique argument to getIndexInfo is set to "true", that index of column containing non-unique values is also returned. I need to be able to determine programmatically, which columns only allow unique values. The exact method used is: public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException The Sun JDBC API documentation says: unique - when true, return only indices for unique values; when false, return indices regardless of whether unique or not Is returning an index for a column with non-unique values when unique is set to "true" the correct behaviour or a bug? Using version 4.0.18-nt of MySQL. -George How to repeat: public void testNonUniqueBug() throws Exception { try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug"); this.stmt.executeUpdate("CREATE TABLE testNonUniqueBug(field1 INT, INDEX(field1))"); DatabaseMetaData dbmd = this.conn.getMetaData(); this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", true, false); assertTrue(!this.rs.next()); // there should be no rows that meet this requirement this.rs = dbmd.getIndexInfo(this.conn.getCatalog(), null, "testNonUniqueBug", false, false); assertTrue(this.rs.next()); // there should be one row that meets this requirement assertTrue(!this.rs.next()); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testNonUniqueBug"); } }