fix(oracle): stop ROWID pagination injection on views
This commit is contained in:
11 files changed
+196
-17
No files matched your search
@@ -24,6 +24,7 @@ const mocks = vi.hoisted(() => ({
|
||||
setTableMeta: vi.fn(),
|
||||
clearInvalidDataTabSort: vi.fn(),
|
||||
activeResultExecutionTarget: vi.fn(),
|
||||
lookupLocalCompletionTables: vi.fn(),
|
||||
metadataGeneration: 0,
|
||||
}));
|
||||
|
||||
@@ -47,6 +48,7 @@ vi.mock("@/stores/connectionStore", () => ({
|
||||
getConfig: mocks.getConfig,
|
||||
ensureConnected: mocks.ensureConnected,
|
||||
metadataGenerationFor: () => mocks.metadataGeneration,
|
||||
lookupLocalCompletionTables: mocks.lookupLocalCompletionTables,
|
||||
}),
|
||||
}));
|
||||
|
||||
@@ -145,6 +147,7 @@ describe("useDataGridActions", () => {
|
||||
mocks.buildSortedQuerySql.mockResolvedValue({ ok: true, sql: "SELECT sorted" });
|
||||
mocks.ensureConnected.mockResolvedValue(undefined);
|
||||
mocks.activeResultExecutionTarget.mockReturnValue(undefined);
|
||||
mocks.lookupLocalCompletionTables.mockReturnValue([]);
|
||||
mocks.getColumns.mockResolvedValue([{ name: "id", data_type: "integer", is_nullable: false, column_default: null, is_primary_key: true, extra: null }]);
|
||||
mocks.listIndexes.mockResolvedValue([]);
|
||||
});
|
||||
@@ -167,6 +170,39 @@ describe("useDataGridActions", () => {
|
||||
expect(mocks.executeTabSql.mock.calls[0]?.[2]).not.toHaveProperty("preserveTotalRowCountDuringExecution");
|
||||
});
|
||||
|
||||
it("repairs a restored Oracle view type before building paginated SQL", async () => {
|
||||
mocks.getConfig.mockReturnValue({ id: "oracle-1", db_type: "oracle", default_schema: "REPORTING" });
|
||||
mocks.lookupLocalCompletionTables.mockReturnValue([{ name: "REPORT_ROWS", schema: "REPORTING", type: "view" }]);
|
||||
mocks.buildTableSelectSql.mockResolvedValueOnce('SELECT "ID" FROM "REPORTING"."REPORT_ROWS"');
|
||||
const tab = tableDataTab({
|
||||
connectionId: "oracle-1",
|
||||
database: "XEPDB1",
|
||||
title: "REPORT_ROWS",
|
||||
tableMeta: {
|
||||
schema: "REPORTING",
|
||||
tableName: "REPORT_ROWS",
|
||||
tableType: "TABLE",
|
||||
columns: [{ name: "ID", data_type: "NUMBER", is_nullable: false, column_default: null, is_primary_key: false, extra: null }],
|
||||
primaryKeys: ["__DBX_ROWID"],
|
||||
},
|
||||
});
|
||||
mocks.tabs.push(tab);
|
||||
const actions = useDataGridActions(computed(() => tab));
|
||||
|
||||
await actions.onReloadData(tab.id, tab.sql, "", "", "", 100, 100, "refresh");
|
||||
|
||||
expect(tab.tableMeta?.tableType).toBe("VIEW");
|
||||
expect(mocks.buildTableSelectSql).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
tableName: "REPORT_ROWS",
|
||||
tableType: "VIEW",
|
||||
includeRowId: false,
|
||||
limit: 100,
|
||||
offset: 100,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("executes the WHERE apply SQL on the emitting tab (#8216)", async () => {
|
||||
// ContentArea 的 executeSql 事件契约是 (tabId, sql),App.vue 按此顺序透传;
|
||||
// 签名若仍是 sql-first,resolveActionTab 会拿 SQL 文本当 tab id 匹配失败,
|
||||
|
||||
@@ -565,6 +565,58 @@ describe("useSidebarDataOpenRuntime", () => {
|
||||
expect(mocks.loadTableMetadata).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("repairs a restored Oracle view tab that was persisted as a table", async () => {
|
||||
mocks.databaseType = "oracle";
|
||||
const viewNode = { ...tableNode, id: "view-users", type: "view" as const, tableType: undefined };
|
||||
mocks.tabs.push({
|
||||
id: "existing-view-tab",
|
||||
connectionId: "connection-1",
|
||||
database: "app",
|
||||
title: "users",
|
||||
mode: "data",
|
||||
schema: "public",
|
||||
sql: "SELECT * FROM users",
|
||||
isDirty: false,
|
||||
isExecuting: true,
|
||||
executionId: "running-query",
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
tableMeta: {
|
||||
schema: "public",
|
||||
tableName: "users",
|
||||
tableType: "TABLE",
|
||||
columns: [{ name: "id", data_type: "bigint", is_nullable: false, column_default: null, is_primary_key: false, extra: null }],
|
||||
primaryKeys: ["__DBX_ROWID"],
|
||||
},
|
||||
tableMetaUpdatedAt: Date.now(),
|
||||
tableMetaGeneration: 0,
|
||||
} as QueryTab);
|
||||
mocks.loadTableMetadata.mockImplementationOnce(async (request: { database: string; schema?: string; tableName: string; tableType?: string }) => ({
|
||||
metadata: {
|
||||
schema: request.schema,
|
||||
tableName: request.tableName,
|
||||
tableType: request.tableType,
|
||||
database: request.database,
|
||||
columns: [{ name: "id", data_type: "bigint", is_nullable: false, column_default: null, is_primary_key: false, extra: null }],
|
||||
indexes: [],
|
||||
primaryKeys: [],
|
||||
cachedAt: Date.now(),
|
||||
},
|
||||
cacheStatus: "miss",
|
||||
ageMs: 0,
|
||||
}));
|
||||
|
||||
await useSidebarDataOpenRuntime().openData(viewNode);
|
||||
|
||||
expect(mocks.tabs[0]?.tableMeta?.tableType).toBe("VIEW");
|
||||
expect(mocks.cancelTabExecution).not.toHaveBeenCalled();
|
||||
expect(mocks.executeTabSql).not.toHaveBeenCalled();
|
||||
await vi.waitFor(() => {
|
||||
expect(mocks.loadTableMetadata).toHaveBeenCalledWith(expect.objectContaining({ tableName: "users", tableType: "VIEW" }));
|
||||
expect(mocks.tabs[0]?.tableMeta?.primaryKeys).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not mark row identity pending on a warm metadata cache", async () => {
|
||||
mocks.cachedMetadata = {
|
||||
metadata: {
|
||||
|
||||
Reference in new issue
Block a user