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

This commit is contained in:
dienaso authored and GitHub committed 2026-09-13 13:27:57 +08:00
1 parent 1137cab7f4
commit 0459dfea12
2 files changed
+37 -3

No files matched your search

@@ -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);
});
});
+7 -3
View File
@@ -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;