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(grid): keep external JDBC saves out of batch transactions

许迪智038499bcb9d0
diff --git a/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts b/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts
index 1c0ccacaf9..4f54899b41 100644
--- a/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useDataGridEditor.spec.ts
@@ -1966,6 +1966,23 @@ describe("useDataGridEditor saveChanges reload", () => {
expect(editor.saveError.value).toBe("");
});
+ it("routes multi-statement edits through executeBatch for external JDBC drivers inferred as a transactional dialect (#12657)", async () => {
+ mocks.getConfig.mockReturnValue({ id: "connection-1", db_type: "jdbc", database_info: { productName: "H2" } });
+ mocks.prepareDataGridSave.mockResolvedValue({
+ statements: ["DELETE FROM users WHERE id=1", "DELETE FROM users WHERE id=2"],
+ rollbackStatements: [],
+ });
+ mocks.executeBatch.mockResolvedValue({ affected_rows: 2 });
+ const { editor } = createSaveTestEditor({ databaseType: "h2" });
+ expect(editor.useTransaction.value).toBe(false);
+ editor.dirtyRows.value.set(0, new Map([[1, "alpha"]]));
+ editor.dirtyRows.value.set(1, new Map([[1, "beta"]]));
+ await editor.saveChanges();
+ expect(mocks.executeInTransaction).not.toHaveBeenCalled();
+ expect(mocks.executeBatch).toHaveBeenCalledWith("connection-1", "app", ["DELETE FROM users WHERE id=1", "DELETE FROM users WHERE id=2"], undefined);
+ expect(editor.saveError.value).toBe("");
+ });
+
it("keeps both joined edits pending if the transaction fails", async () => {
const targets = [
{ tableMeta: { tableName: "users", primaryKeys: ["id"], columns: [] }, sourceColumns: ["id", "name", undefined, undefined] },
diff --git a/apps/desktop/src/composables/useDataGridEditor.ts b/apps/desktop/src/composables/useDataGridEditor.ts
index e8e5891a42..bed8ed3a8a 100644
--- a/apps/desktop/src/composables/useDataGridEditor.ts
+++ b/apps/desktop/src/composables/useDataGridEditor.ts
@@ -592,7 +592,11 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
const isConditionalUpdateActive = computed(() => conditionalUpdateExecution.value !== undefined);
const hasBackendSaveTarget = computed(() => !!connectionId.value && !!tableMeta.value);
- const useTransaction = computed(() => editable.value && supportsDataGridTransaction(resolvedDatabaseType.value) && (!!customSaveHandler?.value || hasBackendSaveTarget.value));
+ // External JDBC drivers have no batch-transaction path even when their dialect
+ // is inferred as a transactional engine (e.g. a driver reporting itself as H2),
+ // so the raw connection type decides whether saves run in a transaction (#12657).
+ const transactionDatabaseType = computed(() => (connectionStore.getConfig(connectionId.value ?? "")?.db_type === "jdbc" ? "jdbc" : resolvedDatabaseType.value));
+ const useTransaction = computed(() => editable.value && supportsDataGridTransaction(transactionDatabaseType.value) && (!!customSaveHandler?.value || hasBackendSaveTarget.value));
if (hasPendingChanges.value && useTransaction.value) {
transactionActive.value = true;