package testsuite.simple; import testsuite.BaseTestCase; import java.sql.DatabaseMetaData; public class TestBug23109 extends BaseTestCase { public TestBug23109(String name) { // TODO Auto-generated constructor stub super(name); } public void testbug23109() throws Exception { try { //set up this.stmt.executeUpdate("DROP DATABASE IF EXISTS 23109DB2"); this.stmt.executeUpdate("CREATE DATABASE 23109DB2"); this.stmt.executeUpdate("DROP DATABASE IF EXISTS 23109DB1"); this.stmt.executeUpdate("CREATE DATABASE 23109DB1"); this.stmt.executeUpdate("create table 23109DB1.tbl1 (id_parent int not null auto_increment primary key) engine =INNODB;"); this.stmt.executeUpdate("create table 23109DB2.tbl2 (id_child int not null, foreign key (id_child) references 23109DB1.tbl1(id_parent)) engine =INNODB;"); DatabaseMetaData dbmd = this.conn.getMetaData(); this.rs = dbmd.getExportedKeys("23109DB1", null, "tbl1"); while (this.rs.next()) { System.out.println("Entering: Exported db1.tbl1"); System.out.println("PK schema name: "+this.rs.getString("PKTABLE_CAT")); System.out.println("PK col name: "+this.rs.getString("PKCOLUMN_NAME")); System.out.println("PK tbl name: "+this.rs.getString("PKTABLE_NAME")); System.out.println("FK schema name: "+this.rs.getString("FKTABLE_CAT")); System.out.println("FK col name: "+this.rs.getString("FKCOLUMN_NAME")); System.out.println("FK tbl name: "+this.rs.getString("FKTABLE_NAME")); assertEquals("tbl1", this.rs.getString("PKTABLE_NAME")); assertEquals("id_parent", this.rs.getString("PKCOLUMN_NAME")); assertEquals("tbl2", this.rs.getString("FKTABLE_NAME")); assertEquals("id_child", this.rs.getString("FKCOLUMN_NAME")); } this.rs.close(); System.out.println("---"); this.rs = dbmd.getImportedKeys("23109DB2", null, "tbl2"); while (this.rs.next()) { System.out.println("Entering: Imported db2.tbl2"); System.out.println("PK schema name: "+this.rs.getString("PKTABLE_CAT")); System.out.println("PK col name: "+this.rs.getString("PKCOLUMN_NAME")); System.out.println("PK tbl name: "+this.rs.getString("PKTABLE_NAME")); System.out.println("FK schema name: "+this.rs.getString("FKTABLE_CAT")); System.out.println("FK col name: "+this.rs.getString("FKCOLUMN_NAME")); System.out.println("FK tbl name: "+this.rs.getString("FKTABLE_NAME")); assertEquals("tbl1", this.rs.getString("PKTABLE_NAME")); assertEquals("id_parent", this.rs.getString("PKCOLUMN_NAME")); assertEquals("tbl2", this.rs.getString("FKTABLE_NAME")); assertEquals("id_child", this.rs.getString("FKCOLUMN_NAME")); } this.rs.close(); } finally { this.stmt.executeUpdate("DROP DATABASE IF EXISTS 23109DB2"); this.stmt.executeUpdate("DROP DATABASE IF EXISTS 23109DB1"); closeMemberJDBCResources(); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub junit.textui.TestRunner.run(TestBug23109.class); } }