fix(jdbc): recover primary keys via catalog fallback

This commit is contained in:
LRcoding authored and GitHub committed 2026-07-07 14:41:52 +08:00
1 parent c3893bf314
commit f659a74a87
2 files changed
+131 -1

No files matched your search

@@ -168,7 +168,11 @@ public final class StandardJdbcMetadata {
Set<String> primaryKeys = primaryKeys(meta, null, schema, table);
List<ColumnInfo> result = new ArrayList<>();
appendColumns(result, meta, null, schema, table, primaryKeys);
if (result.isEmpty() && profile.getCatalogFallbackEnabled() && !configuredDatabase.trim().isEmpty()) {
if (!result.isEmpty() && primaryKeys.isEmpty() && profile.getCatalogFallbackEnabled() && hasConfiguredDatabase(configuredDatabase)) {
Set<String> fallbackPrimaryKeys = primaryKeys(meta, configuredDatabase, schema, table);
markPrimaryKeys(result, fallbackPrimaryKeys);
}
if (result.isEmpty() && profile.getCatalogFallbackEnabled() && hasConfiguredDatabase(configuredDatabase)) {
Set<String> fallbackPrimaryKeys = primaryKeys(meta, configuredDatabase, schema, table);
appendColumns(result, meta, configuredDatabase, schema, table, fallbackPrimaryKeys);
}
@@ -522,6 +526,21 @@ public final class StandardJdbcMetadata {
return keys;
}
private static boolean hasConfiguredDatabase(String configuredDatabase) {
return configuredDatabase != null && !configuredDatabase.trim().isEmpty();
}
private static void markPrimaryKeys(List<ColumnInfo> columns, Set<String> primaryKeys) {
if (primaryKeys.isEmpty()) {
return;
}
for (ColumnInfo column : columns) {
if (primaryKeys.contains(column.getName())) {
column.setIs_primary_key(true);
}
}
}
private static void appendSchemas(Set<String> names, ResultSet rs) throws Exception {
try (ResultSet closeable = rs) {
while (closeable.next()) {