Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(jdbc): match table comments when filtering metadata

Luis Arayae04821322c00
diff --git a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java b/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
index ed2e155bf9..cf5e064cba 100644
--- a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
+++ b/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java
@@ -3305,7 +3305,8 @@ public final class DbxJdbcPlugin {
while (rs.next()) {
found = true;
String name = rs.getString("TABLE_NAME");
- if (!metadataNameMatches(name, normalizedFilter)) {
+ String comment = rs.getString("REMARKS");
+ if (!metadataNameOrCommentMatches(name, comment, normalizedFilter)) {
continue;
}
if (skipped++ < Math.max(0, offset)) {
@@ -3375,7 +3376,9 @@ public final class DbxJdbcPlugin {
int max = limit <= 0 ? Integer.MAX_VALUE : limit;
int skipped = 0;
for (JsonNode item : source) {
- if (!metadataNameMatches(item.path("name").asText(""), normalizedFilter)) {
+ String name = item.path("name").asText("");
+ String comment = item.hasNonNull("comment") ? item.path("comment").asText("") : null;
+ if (!metadataNameOrCommentMatches(name, comment, normalizedFilter)) {
continue;
}
String type = item.path(typeField).asText("");
@@ -3394,6 +3397,16 @@ public final class DbxJdbcPlugin {
return result;
}
+ private static boolean metadataNameOrCommentMatches(String name, String comment, String filter) {
+ if (filter == null || filter.isEmpty()) {
+ return true;
+ }
+ if (metadataNameMatches(name, filter)) {
+ return true;
+ }
+ return comment != null && !comment.isEmpty() && metadataNameMatches(comment, filter);
+ }
+
private static boolean metadataNameMatches(String name, String filter) {
if (filter == null || filter.isEmpty()) {
return true;
diff --git a/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java b/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
index 790e1b92ec..2e18e15198 100644
--- a/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
+++ b/plugins/jdbc/src/test/java/app/dbx/jdbc/DbxJdbcPluginTest.java
@@ -2311,6 +2311,12 @@ final class DbxJdbcPluginTest {
"sql": "CREATE TABLE IF NOT EXISTS app.people_archive (id INT PRIMARY KEY)"
}
""".formatted(CONNECTION));
+ request("executeQuery", """
+ {
+ "connection": %s,
+ "sql": "CREATE TABLE IF NOT EXISTS app.cards (id INT PRIMARY KEY); COMMENT ON TABLE app.cards IS '卡片信息表'"
+ }
+ """.formatted(CONNECTION));
JsonNode response = request("listTables", """
{
@@ -2326,6 +2332,20 @@ final class DbxJdbcPluginTest {
assertFalse(response.has("error"), response.toString());
assertEquals(1, response.path("result").size());
assertEquals("PEOPLE_ARCHIVE", response.path("result").path(0).path("name").asText());
+
+ JsonNode commentMatchResponse = request("listTables", """
+ {
+ "connection": %s,
+ "schema": "APP",
+ "filter": "卡片",
+ "object_types": ["TABLE"]
+ }
+ """.formatted(CONNECTION));
+
+ assertFalse(commentMatchResponse.has("error"), commentMatchResponse.toString());
+ assertEquals(1, commentMatchResponse.path("result").size());
+ assertEquals("CARDS", commentMatchResponse.path("result").path(0).path("name").asText());
+ assertEquals("卡片信息表", commentMatchResponse.path("result").path(0).path("comment").asText());
}
@Test