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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(editor): keep hover metadata scoped to the qualified table database
t8y2520175988bdc
diff --git a/apps/desktop/src/components/editor/__tests__/useQueryEditorHover.spec.ts b/apps/desktop/src/components/editor/__tests__/useQueryEditorHover.spec.tsindex 0f4c6d8fb6..33c8faafe8 100644--- a/apps/desktop/src/components/editor/__tests__/useQueryEditorHover.spec.ts+++ b/apps/desktop/src/components/editor/__tests__/useQueryEditorHover.spec.ts@@ -128,6 +128,43 @@ describe("QueryEditor hover resolution", () => {expect(loadDdl).toHaveBeenCalledWith(expect.objectContaining({ schema: "archive" }));});+ it.each([+ ["starrocks", "fallback"],+ ["mysql", "fallback"],+ ["starrocks", "always"],+ ] as const)("loads %s DDL for a qualified table in another database than the selected tab database (%s mode)", async (type, mode) => {+ // Issue #13243: database b right-clicked while tab database a is selected must+ // fetch b's metadata and DDL instead of silently falling back to a.+ const modelValue = "SELECT * FROM b.orders";+ const { store, settings, metadata, resolve, createHoverDom } = createHarness({ databaseType: type, dialect: "mysql", database: "a", schema: undefined, modelValue });+ settings.editorSettings.tableHoverLookupMode = mode;+ store.lookupLocalCompletionTables.mockReturnValue([{ name: "orders", database: "b" }]);+ store.listCompletionTables.mockResolvedValue([{ name: "orders", database: "b" }]);+ const tooltip = await resolve(modelValue.indexOf("b.orders") + 2);+ expect(tooltip, "tooltip").not.toBeNull();+ tooltip!.create();+ // The hovered database b is pulled with no schema filter; tab database a never leaks in.+ expect(store.listCompletionTables.mock.calls.every((call) => call[1] === "b" && call[6] === undefined)).toBe(true);+ expect(loadDdl).toHaveBeenCalledWith(expect.objectContaining({ database: "b", schema: "", tableName: "orders" }));+ expect(metadata.cachedTables).toEqual([{ name: "orders", database: "b" }]);+ expect(createHoverDom).toHaveBeenCalledWith("orders", expect.any(String), expect.any(String), undefined);+ });++ it("resolves cross-database column metadata through the qualified database as source", async () => {+ const sql = "SELECT o.total FROM b.orders o";+ const { store, metadata, resolve, createHoverDom } = createHarness({ databaseType: "starrocks", dialect: "mysql", database: "a", schema: undefined, modelValue: sql }, true);+ store.listCompletionTables.mockResolvedValue([{ name: "orders", database: "b" }]);+ store.listCompletionColumns.mockResolvedValue([{ name: "total", table: "orders", database: "b", dataType: "decimal" }]);+ const tooltip = await resolve(9);+ expect(tooltip, JSON.stringify(store.listCompletionTables.mock.calls.map((c) => [c[1], c[4]]))).not.toBeNull();+ tooltip!.create();+ // Column metadata must resolve against the qualified database b, not the tab database a.+ expect(store.listCompletionColumns).toHaveBeenCalledWith("connection", "b", "orders", undefined, expect.objectContaining({ tableQuoted: false }), undefined);+ expect(store.listCompletionColumns.mock.calls.some((call) => call[1] === "a")).toBe(false);+ expect(metadata.cachedColumnsByTable.get("b.orders")).toHaveLength(1);+ expect(createHoverDom).toHaveBeenCalledWith("total", "decimal", undefined, ["orders"]);+ });+it("falls back to column metadata when DDL loading fails", async () => {vi.spyOn(console, "warn").mockImplementation(() => {});loadDdl.mockRejectedValue(new Error("DDL unavailable"));diff --git a/apps/desktop/src/components/editor/useQueryEditorHover.ts b/apps/desktop/src/components/editor/useQueryEditorHover.tsindex ac1319013e..687a0e9f2a 100644--- a/apps/desktop/src/components/editor/useQueryEditorHover.ts+++ b/apps/desktop/src/components/editor/useQueryEditorHover.ts@@ -134,7 +134,9 @@ export function useQueryEditorHover(options: QueryEditorHoverOptions) {const hoverTarget = completionMetadataTarget({name: lookup.tableName,catalog: props.catalog,- database: lookup.database !== props.database ? lookup.database : undefined,+ // Keep the hovered table's own database so metadata/DDL requests never fall back+ // to the tab's database (cross-database `b.orders` while tab database `a` is selected).+ database: lookup.database,schema: lookup.schema,});if (!hoverTarget) return null;@@ -143,7 +145,9 @@ export function useQueryEditorHover(options: QueryEditorHoverOptions) {database: hoverTarget.database,schema: hoverTarget.schema,};- const preferredSchema = props.schema;+ // MySQL-family engines address `other_db.table` with the selected database+ // cleared (no schema); the toolbar value must not leak into that lookup.+ const preferredSchema = lookup.schemaFromQualifier ? hoverScope.schema : props.schema;const matchHoverTable = (tables: typeof completionMetadata.cachedTables) =>matchHoverTableCandidates(tables, {lookups: [qualifiedTableLookup, identifier],@@ -160,7 +164,7 @@ export function useQueryEditorHover(options: QueryEditorHoverOptions) {};const searchRemote = async (schema: string | undefined, globalSearch: boolean) => {const loadedTables = await connectionStore.listCompletionTables(props.connectionId!, hoverScope.database, tableLookupName, MAX_COMPLETION_TABLES, schema, globalSearch, preferredSchema, hoverScope.catalog);- return schema ? scopeHoverTables(loadedTables, { ...hoverScope, schema }) : loadedTables;+ return scopeHoverTables(loadedTables, schema ? { ...hoverScope, schema } : { ...hoverScope, schema: undefined });};let hoverTables = completionMetadata.cachedTables.filter((table) => (lookup.preferGlobalFirst || !hoverScope.schema ? hoverTableMatchesScope(table, { ...hoverScope, schema: undefined }) : hoverTableMatchesScope(table, hoverScope)));