Skip to content

armgit / dbx

Public Imported from GitHub
0

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。

fix(editor): apply default transaction mode when binding unbound tabs

dienaso0459dfea12cb
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;