fix(grid): continue Oracle manual transaction cursor for infinite scroll

This commit is contained in:
zipg authored and GitHub committed 2026-08-24 18:37:30 +08:00
1 parent 4021216155
commit 5bafb68919
10 files changed
+410 -30

No files matched your search

@@ -812,6 +812,65 @@ describe("queryStore hidden primary key editing", () => {
expect(store.tabs.find((tab) => tab.id === tabId)?.result?.large_value_cells).toEqual([{ row_index: 0, column_index: 1, original_bytes: 81920 }]);
});
it("continues the Oracle cursor for page 2 in a manual transaction", async () => {
getConnectionConfig.mockReturnValue({ id: "oracle-1", name: "Oracle", db_type: "oracle", database: "ORCL", query_timeout_secs: 30 });
analyzeEditableQueryEditability.mockResolvedValue({ editable: false, reason: "complex-query" });
prepareQueryPaginationExecutionPlan.mockImplementation(async (options) => ({
sqlToExecute: options.sql,
pageSql: options.sql,
pageLimit: options.pagination.limit,
pageOffset: options.pagination.offset,
countSql: undefined,
useAgentResultSession: true,
}));
executeInManualTransaction
.mockResolvedValueOnce([
{
columns: ["ID"],
rows: Array.from({ length: 100 }, (_, index) => [index + 1]),
affected_rows: 0,
execution_time_ms: 1,
session_id: "oracle-go-1",
has_more: true,
},
])
.mockResolvedValueOnce([
{
columns: ["ID"],
rows: Array.from({ length: 100 }, (_, index) => [index + 101]),
affected_rows: 0,
execution_time_ms: 1,
has_more: false,
},
]);
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
const tabId = store.createTab("oracle-1", "ORCL", "Query");
// Tabs default to auto-commit; exercise the explicit manual-transaction path.
store.setAutoCommit(tabId, false);
const sql = "SELECT ID FROM APP.EVENTS ORDER BY ID";
await store.executeTabSql(tabId, sql);
const tab = store.tabs.find((item) => item.id === tabId)!;
expect(tab.autoCommit).toBe(false);
expect(executeInManualTransaction).toHaveBeenNthCalledWith(1, "txn-1", sql, "ORCL", undefined, expect.any(Number), false, 100, undefined);
expect(tab.result?.rows).toHaveLength(100);
await store.executeTabSql(tabId, sql, {
resultBaseSql: sql,
pagination: { limit: 100, offset: 100, sessionId: "oracle-go-1" },
appendResult: { maxRows: 10_000 },
preserveResultDuringExecution: true,
preserveTotalRowCountDuringExecution: true,
replaceActiveResultInGroup: true,
});
expect(executeInManualTransaction).toHaveBeenNthCalledWith(2, "txn-1", sql, "ORCL", undefined, expect.any(Number), false, 100, "oracle-go-1");
expect(tab.result?.rows).toHaveLength(200);
expect(tab.result?.rows[100]).toEqual([101]);
});
it("does not start an Oracle manual transaction after cancellation during metadata loading", async () => {
const columnsGate = deferred<Awaited<ReturnType<typeof getColumns>>>();
getConnectionConfig.mockReturnValue({ id: "oracle-1", name: "Oracle", db_type: "oracle", database: "ORCL", query_timeout_secs: 30 });
+7 -3
View File
@@ -5139,10 +5139,14 @@ export const useQueryStore = defineStore("query", () => {
executionPromise = (async () => {
const txnSessionId = tab.txnSessionId;
if (!txnSessionId) throw new Error("Manual transaction session was not initialized");
const executeInTransaction = (sessionId: string) =>
useAgentResultSession
? api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview, pageLimit, options?.pagination?.sessionId)
: api.executeInManualTransaction(sessionId, sqlToExecute, executionDatabase, executionSchema, pageLimit ?? agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview);
try {
return await api.executeInManualTransaction(txnSessionId, sqlToExecute, executionDatabase, executionSchema, pageLimit ?? agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview);
return await executeInTransaction(txnSessionId);
} catch (error) {
if (manualTransactionRecoveryAttempted || !isManualTransactionSessionExpired(error)) throw error;
if (options?.pagination?.sessionId || manualTransactionRecoveryAttempted || !isManualTransactionSessionExpired(error)) throw error;
manualTransactionRecoveryAttempted = true;
tab.txnSessionId = undefined;
tab.txnAutoRolledBack = true;
@@ -5150,7 +5154,7 @@ export const useQueryStore = defineStore("query", () => {
const refreshedSessionId = await api.beginManualTransaction(executionConnectionId, executionDatabase, executionSchema, executionCatalog);
tab.txnSessionId = refreshedSessionId;
queryExecutionLog("info", "manual-txn:restarted", { traceId, txnSessionId: refreshedSessionId, elapsed: elapsed() });
return api.executeInManualTransaction(refreshedSessionId, sqlToExecute, executionDatabase, executionSchema, pageLimit ?? agentProtocolQueryResultMaxRows(queryResultMaxRows), useOracleLobPreview);
return executeInTransaction(refreshedSessionId);
}
})();
} else {