changeset 421:163b784aa93b

Added full ordering to correct issues when retrieving columns from fks where a table has multiple fks to the same table.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 28 Jan 2021 21:59:38 +0100 (2021-01-28)
parents a0f99a81ce8e
children 8368cbc670bf
files ChangeLog src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,13 @@
 # This file is updated with Maddlog
 
 * Thu Jan 28 2021 Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
+- Corrected the ordering of the output of DatabaseMetaData methods
+  getImportedKeys(), getExportedKeys() and getCrossReference(). In cases
+  where a table would have multiple fks to the same external table,
+  the output was not as expected. This has been corrected, so the columns
+  now appear in the order as defined in the creation of the fks.
+
+* Thu Jan 28 2021 Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
 - The dumping of table definitions from JdbcClient program has been
   improved. It now includes the ON UPDATE and ON DELETE rules for foreign
   key constraints. Also it no longer generates CREATE INDEX statements
--- a/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
+++ b/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
@@ -2696,7 +2696,9 @@ public class MonetDatabaseMetaData
 			}
 		}
 
-		query.append(" ORDER BY \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\", \"KEY_SEQ\"");
+		// Note: the extra \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\" in the ordering is important
+		// else we do not get the correct column order when multiple fks exist to the same pk in 1 table or query multiple tables.
+		query.append(" ORDER BY \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\", \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"KEY_SEQ\"");
 
 		return executeMetaDataQuery(query.toString());
 	}
@@ -2779,7 +2781,9 @@ public class MonetDatabaseMetaData
 			}
 		}
 
-		query.append(" ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"KEY_SEQ\"");
+		// Note: the extra \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\" in the ordering is important
+		// else we do not get the correct column order when multiple fks exist to the same pk in 1 table or query multiple tables.
+		query.append(" ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\", \"KEY_SEQ\"");
 
 		return executeMetaDataQuery(query.toString());
 	}
@@ -2880,7 +2884,9 @@ public class MonetDatabaseMetaData
 			}
 		}
 
-		query.append(" ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"KEY_SEQ\"");
+		// Note: the extra \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\" in the ordering is important
+		// else we do not get the correct column order when multiple fks exist to the same pk in 1 table or query multiple tables.
+		query.append(" ORDER BY \"FKTABLE_SCHEM\", \"FKTABLE_NAME\", \"FK_NAME\", \"PKTABLE_SCHEM\", \"PKTABLE_NAME\", \"PK_NAME\", \"KEY_SEQ\"");
 
 		return executeMetaDataQuery(query.toString());
 	}