@@ -5580,4 +5580,84 @@ void testBug91550() throws Exception {
5580
5580
assertEquals ("$" , md .getExtraNameCharacters ());
5581
5581
}
5582
5582
5583
+ /**
5584
+ * Tests fix for Bug#113600 (Bug#36171575), Contribution: Fix join condition for retrieval of imported primary keys.
5585
+ *
5586
+ * @throws Exception
5587
+ */
5588
+ @ Test
5589
+ public void testBug113600 () throws Exception {
5590
+ String databaseName1 = "dbBug113600_1" ;
5591
+ String databaseName2 = "dbBug113600_2" ;
5592
+ if (isServerRunningOnWindows ()) {
5593
+ databaseName1 = databaseName1 .toLowerCase ();
5594
+ databaseName2 = databaseName2 .toLowerCase ();
5595
+ }
5596
+ String tableName1 = "table1" ;
5597
+ String tableName2 = "table2" ;
5598
+ String constraintName = "fk_table2_fk_id" ;
5599
+
5600
+ createDatabase (databaseName1 );
5601
+ createTable (databaseName1 + "." + tableName1 , "(`ID` bigint unsigned AUTO_INCREMENT PRIMARY KEY)" );
5602
+ createTable (databaseName1 + "." + tableName2 , "(`ID` bigint unsigned AUTO_INCREMENT PRIMARY KEY, `FK_ID` bigint unsigned NOT NULL," + "CONSTRAINT `"
5603
+ + constraintName + "` FOREIGN KEY (`FK_ID`) REFERENCES `" + databaseName1 + "`.`" + tableName1 + "` (`ID`) ON DELETE CASCADE)" );
5604
+ createDatabase (databaseName2 );
5605
+ createTable (databaseName2 + "." + tableName1 , "(`ID` bigint unsigned AUTO_INCREMENT PRIMARY KEY)" );
5606
+ createTable (databaseName2 + "." + tableName2 , "(`ID` bigint unsigned AUTO_INCREMENT PRIMARY KEY, `FK_ID` bigint unsigned NOT NULL," + "CONSTRAINT `"
5607
+ + constraintName + "` FOREIGN KEY (`FK_ID`) REFERENCES `" + databaseName2 + "`.`" + tableName1 + "` (`ID`) ON DELETE RESTRICT)" );
5608
+
5609
+ Properties props = new Properties ();
5610
+ props .setProperty (PropertyKey .sslMode .getKeyName (), SslMode .DISABLED .name ());
5611
+ props .setProperty (PropertyKey .allowPublicKeyRetrieval .getKeyName (), "true" );
5612
+ boolean useIS = false ;
5613
+ boolean dbTermIsSchema = false ;
5614
+ do {
5615
+ String databaseTerm = dbTermIsSchema ? "SCHEMA" : "CATALOG" ;
5616
+ props .setProperty (PropertyKey .useInformationSchema .getKeyName (), "" + useIS );
5617
+ props .setProperty (PropertyKey .databaseTerm .getKeyName (), databaseTerm );
5618
+ Connection con = getConnectionWithProps (props );
5619
+ DatabaseMetaData md = con .getMetaData ();
5620
+
5621
+ final String testCase = String .format ("Case [useIS: %s, databaseTerm: %s]" , useIS ? "Y" : "N" , databaseTerm );
5622
+
5623
+ this .rs = dbTermIsSchema ? md .getImportedKeys (null , databaseName1 , tableName2 ) : md .getImportedKeys (databaseName1 , null , tableName2 );
5624
+ assertTrue (this .rs .next (), testCase );
5625
+ assertEquals (dbTermIsSchema ? "def" : databaseName1 , this .rs .getString ("PKTABLE_CAT" ), testCase );
5626
+ assertEquals (dbTermIsSchema ? databaseName1 : null , this .rs .getString ("PKTABLE_SCHEM" ), testCase );
5627
+ assertEquals (dbTermIsSchema ? "def" : databaseName1 , this .rs .getString ("FKTABLE_CAT" ), testCase );
5628
+ assertEquals (dbTermIsSchema ? databaseName1 : null , this .rs .getString ("FKTABLE_SCHEM" ), testCase );
5629
+ assertEquals (tableName1 , this .rs .getString ("PKTABLE_NAME" ), testCase );
5630
+ assertEquals ("ID" , this .rs .getString ("PKCOLUMN_NAME" ), testCase );
5631
+ assertEquals (tableName2 , this .rs .getString ("FKTABLE_NAME" ), testCase );
5632
+ assertEquals ("FK_ID" , this .rs .getString ("FKCOLUMN_NAME" ), testCase );
5633
+ assertEquals (1 , this .rs .getInt ("KEY_SEQ" ), testCase );
5634
+ assertEquals (1 , this .rs .getInt ("UPDATE_RULE" ), testCase );
5635
+ assertEquals (0 , this .rs .getInt ("DELETE_RULE" ), testCase );
5636
+ assertEquals (constraintName , this .rs .getString ("FK_NAME" ), testCase );
5637
+ assertEquals (useIS ? "PRIMARY" : null , this .rs .getString ("PK_NAME" ), testCase );
5638
+ assertEquals (7 , this .rs .getInt ("DEFERRABILITY" ), testCase );
5639
+ assertFalse (this .rs .next (), testCase );
5640
+
5641
+ this .rs = dbTermIsSchema ? md .getImportedKeys (null , databaseName2 , tableName2 ) : md .getImportedKeys (databaseName2 , null , tableName2 );
5642
+ assertTrue (this .rs .next (), testCase );
5643
+ assertEquals (dbTermIsSchema ? "def" : databaseName2 , this .rs .getString ("PKTABLE_CAT" ), testCase );
5644
+ assertEquals (dbTermIsSchema ? databaseName2 : null , this .rs .getString ("PKTABLE_SCHEM" ), testCase );
5645
+ assertEquals (dbTermIsSchema ? "def" : databaseName2 , this .rs .getString ("FKTABLE_CAT" ), testCase );
5646
+ assertEquals (dbTermIsSchema ? databaseName2 : null , this .rs .getString ("FKTABLE_SCHEM" ), testCase );
5647
+ assertEquals (tableName1 , this .rs .getString ("PKTABLE_NAME" ), testCase );
5648
+ assertEquals ("ID" , this .rs .getString ("PKCOLUMN_NAME" ), testCase );
5649
+ assertEquals (tableName2 , this .rs .getString ("FKTABLE_NAME" ), testCase );
5650
+ assertEquals ("FK_ID" , this .rs .getString ("FKCOLUMN_NAME" ), testCase );
5651
+ assertEquals (1 , this .rs .getInt ("KEY_SEQ" ), testCase );
5652
+ assertEquals (1 , this .rs .getInt ("UPDATE_RULE" ), testCase );
5653
+ assertEquals (1 , this .rs .getInt ("DELETE_RULE" ), testCase );
5654
+ assertEquals (constraintName , this .rs .getString ("FK_NAME" ), testCase );
5655
+ assertEquals (useIS ? "PRIMARY" : null , this .rs .getString ("PK_NAME" ), testCase );
5656
+ assertEquals (7 , this .rs .getInt ("DEFERRABILITY" ), testCase );
5657
+ assertFalse (this .rs .next (), testCase );
5658
+
5659
+ con .close ();
5660
+ } while ((useIS = !useIS ) || (dbTermIsSchema = !dbTermIsSchema ));
5661
+ }
5662
+
5583
5663
}
0 commit comments