From 0459dfea12cbc0d0d214e151f3c510db49850f32 Mon Sep 17 00:00:00 2001 From: dienaso <89768641@qq.com> Date: Sun, 13 Sep 2026 13:27:57 +0800 Subject: [PATCH] fix(editor): apply default transaction mode when binding unbound tabs --- .../queryStore.defaultTransactionMode.spec.ts | 30 +++++++++++++++++++ apps/desktop/src/stores/queryStore.ts | 10 +++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/stores/__tests__/queryStore.defaultTransactionMode.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.defaultTransactionMode.spec.ts index a073ae1a8a..0b0cfed26b 100644 --- a/apps/desktop/src/stores/__tests__/queryStore.defaultTransactionMode.spec.ts +++ b/apps/desktop/src/stores/__tests__/queryStore.defaultTransactionMode.spec.ts @@ -102,4 +102,34 @@ describe("queryStore default transaction mode", () => { const tab = store.tabs.find((item) => item.id === tabId)!; expect(tab.autoCommit).toBe(true); }); + + it("applies the manual default when an unbound file tab binds to a transactional connection", async () => { + editorSettings.defaultTransactionMode = "manual"; + mocks.getConnectionConfig.mockImplementation((connectionId: string) => (connectionId === "mysql-1" ? { id: "mysql-1", name: "MySQL", db_type: "mysql", database: "app" } : undefined)); + + const { useQueryStore } = await import("@/stores/queryStore"); + const store = useQueryStore(); + // Externally opened SQL files and saved-SQL tabs start unbound + // (connectionId ""), so their initial mode falls back to auto-commit. + const tabId = store.createTab("", "", "Query", "query"); + expect(store.tabs.find((item) => item.id === tabId)!.autoCommit).toBe(true); + + store.updateConnection(tabId, "mysql-1", "app"); + + expect(store.tabs.find((item) => item.id === tabId)!.autoCommit).toBe(false); + }); + + it("keeps the manual default when switching between transactional connections", async () => { + editorSettings.defaultTransactionMode = "manual"; + mocks.getConnectionConfig.mockImplementation((connectionId: string) => (connectionId === "mysql-1" ? { id: "mysql-1", name: "MySQL", db_type: "mysql", database: "app" } : { id: "oracle-1", name: "Oracle", db_type: "oracle", database: "ORCL" })); + + const { useQueryStore } = await import("@/stores/queryStore"); + const store = useQueryStore(); + const tabId = store.createTab("oracle-1", "ORCL", "Query", "query", "APP"); + expect(store.tabs.find((item) => item.id === tabId)!.autoCommit).toBe(false); + + store.updateConnection(tabId, "mysql-1", "app"); + + expect(store.tabs.find((item) => item.id === tabId)!.autoCommit).toBe(false); + }); }); diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts index 3e41ac7ec2..8c6dbf00d7 100644 --- a/apps/desktop/src/stores/queryStore.ts +++ b/apps/desktop/src/stores/queryStore.ts @@ -4261,10 +4261,14 @@ export const useQueryStore = defineStore("query", () => { if (tab.oracleTxnPossiblyDirty !== undefined) tab.oracleTxnPossiblyDirty = false; } - function rollbackTabTransaction(tab: QueryTab, options?: { resetAutoCommit?: boolean }) { + function rollbackTabTransaction(tab: QueryTab, options?: { resetAutoCommit?: boolean; resetAutoCommitDbType?: string }) { if (tab.txnSessionId) void rollbackTransaction(tab.id); if (options?.resetAutoCommit) { - const dbType = useConnectionStore().getConfig(tab.connectionId)?.db_type; + // Callers switching a tab to another connection pass the target db type + // explicitly: the tab still carries the previous connectionId at reset + // time, and unbound file/saved-SQL tabs have none at all (which would + // force auto-commit even when the default mode is manual, #8863). + const dbType = options.resetAutoCommitDbType ?? useConnectionStore().getConfig(tab.connectionId)?.db_type; tab.autoCommit = defaultAutoCommitForDbTypeWithSetting(dbType); } clearOracleTxnPossiblyDirty(tab); @@ -4608,7 +4612,7 @@ export const useQueryStore = defineStore("query", () => { function updateConnection(id: string, connectionId: string, database = "", options: UpdateExecutionTargetOptions = {}) { const tab = tabs.value.find((t) => t.id === id); if (!tab || tab.connectionId === connectionId) return; - rollbackTabTransaction(tab, { resetAutoCommit: true }); + rollbackTabTransaction(tab, { resetAutoCommit: true, resetAutoCommitDbType: useConnectionStore().getConfig(connectionId)?.db_type }); void closeResultSession(tab); void closeClientConnectionSession(tab); tab.connectionId = connectionId;