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.
This commit is contained in:
gggaiitx
2026-07-06 18:22:56 +08:00
committed by GitHub
parent 78019c44e2
commit 2fd2b0e770
2 changed files with 16 additions and 2 deletions
@@ -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);
});
});
@@ -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);