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(sql): return to result view after notices precede results
HARRISON184b55c89eda
diff --git a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.tsindex 169993318a..009089332d 100644--- a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts+++ b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts@@ -764,6 +764,95 @@ SELECT @value AS Message;`;expect(activeOutputView.value).toBe("result");});+ it("returns to the result view when a notice arrived before a PostgreSQL function's result set", async () => {+ // Regression for #11822: `SELECT some_function()` emits a NOTICE while it runs and then+ // returns rows. The live-output watcher in ContentArea advances to Messages as soon as the+ // notice lands, because the rows do not exist yet. With a result set present the completion+ // path used to skip every branch, so the view stayed on Messages instead of showing the data.+ const sql = "SELECT log_and_return()";+ const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });+ const activeConnection = ref<ConnectionConfig | undefined>(connection("postgres"));+ const activeOutputView = ref<"result" | "summary" | "explain" | "chart" | "messages">("result");+ const queryStore = useQueryStore();+ vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {+ // Mirrors the real order of events: the notice is surfaced live and the view moves to+ // Messages, then the statement finishes with a tabular result.+ activeOutputView.value = "messages";+ if (activeTab.value) activeTab.value.result = { columns: ["log_and_return"], rows: [["done"]], affected_rows: 0, execution_time_ms: 1, messages: [{ severity: "NOTICE", message: "working" }] };+ });+ vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);++ const execution = useSqlExecution({+ activeTab: computed(() => activeTab.value),+ activeConnection: computed(() => activeConnection.value),+ executableSql: computed(() => sql),+ activeOutputView,+ });++ await execution.tryExecute();++ expect(activeTab.value?.result?.rows).toEqual([["done"]]);+ expect(activeOutputView.value).toBe("result");+ });++ it("keeps Messages selected when a completed run produced no tabular result", async () => {+ const sql = "DO $$ BEGIN RAISE NOTICE 'hello'; END $$;";+ const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });+ const activeConnection = ref<ConnectionConfig | undefined>(connection("postgres"));+ const activeOutputView = ref<"result" | "summary" | "explain" | "chart" | "messages">("result");+ const queryStore = useQueryStore();+ vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {+ activeOutputView.value = "messages";+ if (activeTab.value) activeTab.value.result = { columns: [], rows: [], affected_rows: 0, execution_time_ms: 1, messages: [{ severity: "NOTICE", message: "hello" }] };+ });+ vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);++ const execution = useSqlExecution({+ activeTab: computed(() => activeTab.value),+ activeConnection: computed(() => activeConnection.value),+ executableSql: computed(() => sql),+ activeOutputView,+ });++ await execution.tryExecute();++ expect(activeOutputView.value).toBe("messages");+ });++ it("does not pull a background tab's Messages view away from the tab the user is looking at", async () => {+ const sql = "SELECT log_and_return()";+ const executionTab = { ...queryTab("app"), sql };+ const activeTab = ref<QueryTab | undefined>(executionTab);+ const activeConnection = ref<ConnectionConfig | undefined>(connection("postgres"));+ const activeOutputView = ref<"result" | "summary" | "explain" | "chart" | "messages">("result");+ const queryStore = useQueryStore();+ let finishExecution!: () => void;+ const executionFinished = new Promise<void>((resolve) => {+ finishExecution = resolve;+ });+ const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {+ await executionFinished;+ executionTab.result = { columns: ["log_and_return"], rows: [["done"]], affected_rows: 0, execution_time_ms: 1, messages: [{ severity: "NOTICE", message: "working" }] };+ });+ vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);++ const execution = useSqlExecution({+ activeTab: computed(() => activeTab.value),+ activeConnection: computed(() => activeConnection.value),+ executableSql: computed(() => sql),+ activeOutputView,+ });++ const pending = execution.tryExecute();+ await vi.waitFor(() => expect(executeCurrentSql).toHaveBeenCalledOnce());+ activeTab.value = { ...queryTab("app"), id: "tab-2" };+ activeOutputView.value = "messages";+ finishExecution();+ await pending;++ expect(activeOutputView.value).toBe("messages");+ });+it("forwards execute-in-new-result-tab intent to the query store", async () => {const sql = "SELECT * FROM users";const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });diff --git a/apps/desktop/src/composables/useSqlExecution.ts b/apps/desktop/src/composables/useSqlExecution.tsindex 38d9092b19..a51b6b1c11 100644--- a/apps/desktop/src/composables/useSqlExecution.ts+++ b/apps/desktop/src/composables/useSqlExecution.ts@@ -468,6 +468,13 @@ export function useSqlExecution(deps: {if (executionTabStillActive && deps.activeOutputView.value !== "messages") {deps.activeOutputView.value = statementCount === 1 ? defaultViewForResult(tab.result) : "summary";}+ } else if (executionTabStillActive && deps.activeOutputView.value === "messages" && ((tab.result?.columns.length ?? 0) > 0 || tab.results?.some((result) => result.columns.length > 0))) {+ // A notice can arrive before the statement produces its rows, so the live-output watcher+ // in ContentArea advances to Messages while it cannot yet know that data will follow.+ // Once the run finishes with a real result set, show the data again; Messages stays one+ // click away in the view switcher. Message-only runs and SQL Server PRINT batches are+ // handled by the branches above and keep their existing behavior.+ deps.activeOutputView.value = "result";}const elapsed = Date.now() - start;const failure = firstQueryExecutionError(tab);