diff --git a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts index a68f5abde..1c2be8625 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 0a57f9d43..c62b97ba6 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);