feat(oracle): support manual query transactions
This commit is contained in:
22 files changed
+1011
-99
No files matched your search
@@ -408,6 +408,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT t.* FROM SH_SMCVDMS_OVERSEAS_DRSSITB.TT_PLATFORM_CARS t WHERE t.PLATFORM = '轻卡'");
|
||||
|
||||
@@ -461,6 +463,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM CUSTOMERS");
|
||||
|
||||
@@ -494,6 +497,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM aa");
|
||||
|
||||
@@ -532,6 +537,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ncdb", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
const sql = "SELECT * FROM VITF_PRODUCT_INFOOA WHERE PK_MATERIAL IN ('1', '2')";
|
||||
|
||||
const execution = store.executeTabSql(tabId, sql);
|
||||
@@ -568,6 +574,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
const execution = store.executeTabSql(tabId, "SELECT t.* FROM APP.WIDE_TABLE t");
|
||||
await vi.waitFor(() => expect(executeMulti).toHaveBeenCalled());
|
||||
@@ -618,6 +626,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, sql);
|
||||
|
||||
@@ -665,6 +675,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
const tab = store.tabs.find((item) => item.id === tabId)!;
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM APP.PLATFORM_VIEW");
|
||||
@@ -695,6 +707,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT PAYLOAD FROM APP.DOCUMENTS");
|
||||
|
||||
@@ -723,6 +736,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM APP.DOCUMENT_VIEW");
|
||||
|
||||
@@ -752,6 +766,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM DOCUMENTS");
|
||||
|
||||
@@ -780,6 +795,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT NAME FROM APP.CUSTOMERS");
|
||||
|
||||
@@ -817,6 +833,7 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Query");
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT * FROM CUSTOMERS");
|
||||
|
||||
@@ -959,6 +976,8 @@ describe("queryStore hidden primary key editing", () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "XEPDB1", "Query");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabId, true);
|
||||
|
||||
await store.executeTabSql(tabId, "SELECT NAME FROM DBX_HIDDEN_PK_EDIT_TEST");
|
||||
|
||||
|
||||
@@ -386,6 +386,9 @@ describe("queryStore multi-statement errors", () => {
|
||||
const store = useQueryStore();
|
||||
const tabA = store.createTab("oracle-1", "ORCL", "Tab A");
|
||||
const tabB = store.createTab("oracle-1", "ORCL", "Tab B");
|
||||
// Exercise auto-commit execute-multi path (Oracle tabs default to manual TX).
|
||||
store.setAutoCommit(tabA, true);
|
||||
store.setAutoCommit(tabB, true);
|
||||
|
||||
await store.executeTabSql(tabA, "ALTER SESSION SET CURRENT_SCHEMA = REPORTING");
|
||||
expect(store.tabs.find((tab) => tab.id === tabA)?.completionContextVersion).toBe(1);
|
||||
|
||||
@@ -371,7 +371,19 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
let savedSqlFilesByDatabase = indexSavedSqlFilesByDatabase(savedSqlStore.allFiles);
|
||||
const connections = ref<ConnectionConfig[]>([]);
|
||||
const isDesktop = isTauriRuntime();
|
||||
const activeConnectionId = ref<string | null>(localStorage.getItem(ACTIVE_CONNECTION_STORAGE_KEY));
|
||||
// Prefer a safe read so Node/vitest (missing or partial storage mocks) do not
|
||||
// throw when query tabs resolve connection db_type defaults via this store.
|
||||
const activeConnectionId = ref<string | null>(
|
||||
(() => {
|
||||
try {
|
||||
const storage = globalThis.localStorage;
|
||||
if (!storage || typeof storage.getItem !== "function") return null;
|
||||
return storage.getItem(ACTIVE_CONNECTION_STORAGE_KEY);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})(),
|
||||
);
|
||||
const selectedTreeNodeId = ref<string | null>(null);
|
||||
const selectedTreeNodeIds = ref<string[]>([]);
|
||||
// O(1) membership set — rebuilds only when selectedTreeNodeIds changes.
|
||||
@@ -386,8 +398,14 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const treeClipboard = ref<TreeClipboard | null>(null);
|
||||
|
||||
watch(activeConnectionId, (id) => {
|
||||
if (id) localStorage.setItem(ACTIVE_CONNECTION_STORAGE_KEY, id);
|
||||
else localStorage.removeItem(ACTIVE_CONNECTION_STORAGE_KEY);
|
||||
try {
|
||||
const storage = globalThis.localStorage;
|
||||
if (!storage || typeof storage.setItem !== "function" || typeof storage.removeItem !== "function") return;
|
||||
if (id) storage.setItem(ACTIVE_CONNECTION_STORAGE_KEY, id);
|
||||
else storage.removeItem(ACTIVE_CONNECTION_STORAGE_KEY);
|
||||
} catch {
|
||||
// Ignore storage failures in non-browser / partial mock environments.
|
||||
}
|
||||
});
|
||||
const treeNodes = ref<TreeNode[]>([]);
|
||||
const sidebarDatabaseStorageCache = new Map<string, { expiresAt: number; value: DatabaseStorageInfo[] }>();
|
||||
|
||||
@@ -35,7 +35,7 @@ import { redisCommandResultToQueryResult } from "@/lib/redis/redisQueryResult";
|
||||
import { nextRedisCommandDb } from "@/lib/redis/redisCommandSession";
|
||||
import { isRedisMutatingCommand } from "@/lib/redis/redisCommandTable";
|
||||
import { usesAgentCursorForQuery } from "@/lib/database/databaseDriverManifest";
|
||||
import { supportsClearableQuerySchema } from "@/lib/database/databaseFeatureSupport";
|
||||
import { defaultAutoCommitForDbType, supportsClearableQuerySchema } from "@/lib/database/databaseFeatureSupport";
|
||||
import { canInsertTableRows, canUseKeylessRowPredicate, DBX_ROWID_COLUMN, editablePrimaryKeys, usesSyntheticRowIdKey } from "@/lib/table/tableEditing";
|
||||
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/table/tableDataExport";
|
||||
import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
|
||||
@@ -1509,9 +1509,12 @@ export const useQueryStore = defineStore("query", () => {
|
||||
function applyRestoredOpenTabs(restored: { tabs: QueryTab[]; activeTabId: string | null }) {
|
||||
const connectionStore = useConnectionStore();
|
||||
for (const tab of restored.tabs) {
|
||||
if (tab.mode !== "data") continue;
|
||||
const connection = connectionStore.getConfig(tab.connectionId);
|
||||
if (connection) tab.schema = connectionObjectTreeNodeSchema(connection, tab.database, tab.schema);
|
||||
if (tab.mode === "query" && tab.autoCommit === undefined) {
|
||||
tab.autoCommit = defaultAutoCommitForDbType(connection?.db_type);
|
||||
} else if (tab.mode === "data" && connection) {
|
||||
tab.schema = connectionObjectTreeNodeSchema(connection, tab.database, tab.schema);
|
||||
}
|
||||
}
|
||||
tabs.value = restored.tabs;
|
||||
activeTabId.value = restored.activeTabId;
|
||||
@@ -1657,6 +1660,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
|
||||
const id = uuid();
|
||||
const dbType = useConnectionStore().getConfig(connectionId)?.db_type;
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title: title || `query_${tabs.value.length + 1}`,
|
||||
@@ -1671,6 +1675,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode,
|
||||
...(mode === "query" ? { autoCommit: defaultAutoCommitForDbType(dbType) } : {}),
|
||||
};
|
||||
if (mode === "query") tab.originalSql = initialSql ?? "";
|
||||
const activeIndex = options.insertAfterActive ? tabs.value.findIndex((item) => item.id === activeTabId.value) : -1;
|
||||
@@ -1748,6 +1753,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
// File-backed tabs are identified by their full path, not their basename.
|
||||
// Bypassing createTab avoids overwriting another file with the same name.
|
||||
const id = uuid();
|
||||
const dbType = useConnectionStore().getConfig(connectionId)?.db_type;
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title: "",
|
||||
@@ -1763,6 +1769,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode: "query",
|
||||
autoCommit: defaultAutoCommitForDbType(dbType),
|
||||
};
|
||||
tabs.value.push(tab);
|
||||
activeTabId.value = id;
|
||||
@@ -3022,7 +3029,10 @@ export const useQueryStore = defineStore("query", () => {
|
||||
|
||||
function rollbackTabTransaction(tab: QueryTab, options?: { resetAutoCommit?: boolean }) {
|
||||
if (tab.txnSessionId) void rollbackTransaction(tab.id);
|
||||
if (options?.resetAutoCommit) tab.autoCommit = true;
|
||||
if (options?.resetAutoCommit) {
|
||||
const dbType = useConnectionStore().getConfig(tab.connectionId)?.db_type;
|
||||
tab.autoCommit = defaultAutoCommitForDbType(dbType);
|
||||
}
|
||||
tab.txnAutoRolledBack = false;
|
||||
}
|
||||
|
||||
@@ -3161,6 +3171,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
|
||||
const id = uuid();
|
||||
const restoredPosition = restoreSavedSqlEditorPosition(file.id, file.sql);
|
||||
const dbType = useConnectionStore().getConfig(target.connectionId)?.db_type;
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title: file.name,
|
||||
@@ -3176,6 +3187,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode: "query",
|
||||
autoCommit: defaultAutoCommitForDbType(dbType),
|
||||
editorSelection: restoredPosition.selection,
|
||||
editorViewport: restoredPosition.viewport,
|
||||
};
|
||||
@@ -5175,13 +5187,17 @@ export const useQueryStore = defineStore("query", () => {
|
||||
queryExecutionLog("error", "error", { traceId, elapsed: elapsed(), error: e });
|
||||
// Sync connection state if the error indicates a lost connection
|
||||
useConnectionStore().recordConnectionLostError(executionConnectionId ?? tab.connectionId, e);
|
||||
// Handle manual transaction auto-rollback (e.g. deadlock detected by server,
|
||||
// statement error inside a manual transaction, or idle timeout).
|
||||
// Handle manual transaction auto-rollback (idle timeout only for the banner;
|
||||
// other statement failures still clear the session without the 5-minute notice).
|
||||
if (tab.autoCommit === false) {
|
||||
const errMsg: string = e?.message ?? String(e);
|
||||
if (/rolled.?back/i.test(errMsg) || errMsg.includes("已自动回滚")) {
|
||||
const idleTimeout = /5 minutes of inactivity/i.test(errMsg) || errMsg.includes("5 分钟无操作") || errMsg.includes("已自动回滚");
|
||||
if (idleTimeout) {
|
||||
tab.txnSessionId = undefined;
|
||||
tab.txnAutoRolledBack = true;
|
||||
} else if (/rolled.?back/i.test(errMsg) || /transaction session not found/i.test(errMsg) || /agent runtime terminated/i.test(errMsg)) {
|
||||
tab.txnSessionId = undefined;
|
||||
tab.txnAutoRolledBack = false;
|
||||
}
|
||||
}
|
||||
const current = findExecutionTab(id);
|
||||
@@ -5881,6 +5897,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
function openResultArchiveTab(archive: DecodedQueryResultArchive): string | undefined {
|
||||
const id = uuid();
|
||||
const title = archive.tab.title.trim() || t("tabs.importedResultArchive");
|
||||
const dbType = useConnectionStore().getConfig(archive.tab.connectionId)?.db_type;
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title,
|
||||
@@ -5897,6 +5914,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode: "query",
|
||||
autoCommit: defaultAutoCommitForDbType(dbType),
|
||||
};
|
||||
if (!restoreCachedResultPayload(tab, archive.snapshot)) return undefined;
|
||||
const activeRun = tab.resultRuns?.find((run) => run.id === tab.activeResultRunId) ?? tab.resultRuns?.[0];
|
||||
|
||||
Reference in new issue
Block a user