From 2fd2b0e770e6da2fafcdec657caa3746284d2677 Mon Sep 17 00:00:00 2001 From: gggaiitx <62124152+gggaiitx@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:22:56 +0800 Subject: [PATCH] fix: allow default database for tree-schema databases TREE_SCHEMA mode databases (saphana, jdbc, postgres, etc.) use an empty string to represent the default database selection. The previous check treated empty string as no database selected and incorrectly blocked query execution. --- .../composables/__tests__/useSqlExecution.spec.ts | 12 ++++++++++++ apps/desktop/src/composables/useSqlExecution.ts | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts index a68f5abde9..1c2be86253 100644 --- a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts +++ b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts @@ -58,4 +58,16 @@ describe("requiresDatabaseSelection", () => { it("still requires a database for ordinary MySQL queries", () => { expect(requiresDatabaseSelection(queryTab(), connection("mysql"), "SELECT * FROM users")).toBe(true); }); + + it("allows HANA with default database (empty string) to execute queries", () => { + expect(requiresDatabaseSelection(queryTab(""), connection("saphana"), "SELECT * FROM MOMX_MES.Z_SHIPMENT_INFORMATION")).toBe(false); + }); + + it("allows JDBC with default database (empty string) to execute queries", () => { + expect(requiresDatabaseSelection(queryTab(""), connection("jdbc"), "SELECT * FROM users")).toBe(false); + }); + + it("allows PostgreSQL with default database (empty string) to execute queries", () => { + expect(requiresDatabaseSelection(queryTab(""), connection("postgres"), "SELECT * FROM public.users")).toBe(false); + }); }); diff --git a/apps/desktop/src/composables/useSqlExecution.ts b/apps/desktop/src/composables/useSqlExecution.ts index 0a57f9d438..c62b97ba6c 100644 --- a/apps/desktop/src/composables/useSqlExecution.ts +++ b/apps/desktop/src/composables/useSqlExecution.ts @@ -5,7 +5,7 @@ import { useHistoryStore } from "@/stores/historyStore"; import { useConnectionStore } from "@/stores/connectionStore"; import { useSettingsStore } from "@/stores/settingsStore"; import { useToast } from "@/composables/useToast"; -import { isSingleDatabase } from "@/lib/database/databaseCapabilities"; +import { isSingleDatabase, usesTreeSchemaMode } from "@/lib/database/databaseCapabilities"; import { canExecuteWithoutSelectedDatabase } from "@/lib/connection/connectionLevelDatabaseBootstrap"; import { classifySqlActivityKind } from "@/lib/history/historyActivityKind"; import { sqlMetadataRefreshTarget } from "@/lib/sql/sqlMetadataRefresh"; @@ -229,7 +229,9 @@ function supportsSqlTemplateParameters(connection: ConnectionConfig | undefined) export function requiresDatabaseSelection(tab: QueryTab, connection: ConnectionConfig | undefined, sql = ""): boolean { if (tab.mode !== "query") return false; - if (!connection || tab.database) return false; + if (!connection) return false; + if (tab.database) return false; + if (tab.database === "" && usesTreeSchemaMode(connection.db_type)) return false; if (isSingleDatabase(connection.db_type)) return false; if (canExecuteWithoutSelectedDatabase(connection, sql)) return false; return !["elasticsearch", "qdrant", "milvus", "weaviate", "chromadb", "zookeeper"].includes(connection.db_type);