fix(oracle): stop ROWID pagination injection on views

This commit is contained in:
zipg authored and GitHub committed 2026-09-09 22:35:51 +08:00
1 parent c8c7a40e46
commit b84d162049
11 files changed
+196 -17

No files matched your search

@@ -42,6 +42,7 @@ function index(columns: string[], isUnique = true, filter: string | null = null)
describe("tableEditing", () => {
it("synthesizes ROWID only for Oracle-compatible base tables", () => {
expect(editablePrimaryKeys("oracle", [column("ID"), column("NAME")])).toEqual([]);
expect(editablePrimaryKeys("oracle", [column("ID"), column("NAME")], "VIEW")).toEqual([]);
expect(editablePrimaryKeys("oracle", [column("ID"), column("NAME")], "TABLE")).toEqual([DBX_ROWID_COLUMN]);
expect(editablePrimaryKeys("oceanbase-oracle", [column("ID"), column("NAME")], "TABLE")).toEqual([DBX_ROWID_COLUMN]);
@@ -82,6 +83,9 @@ describe("tableEditing", () => {
});
it("does not include Oracle ROWID for view data tabs", () => {
expect(usesSyntheticRowIdKey("oracle", [DBX_ROWID_COLUMN])).toBe(true);
expect(shouldIncludeSyntheticRowId("oracle", [DBX_ROWID_COLUMN])).toBe(false);
expect(shouldIncludeSyntheticRowId("oracle", [DBX_ROWID_COLUMN], "TABLE")).toBe(true);
expect(usesSyntheticRowIdKey("oracle", [DBX_ROWID_COLUMN], "VIEW")).toBe(false);
expect(usesSyntheticRowIdKey("oracle", [DBX_ROWID_COLUMN], "MATERIALIZED_VIEW")).toBe(false);
expect(usesSyntheticRowIdKey("oceanbase-oracle", [DBX_ROWID_COLUMN], "TABLE")).toBe(true);
+10 -2
View File
@@ -9,6 +9,10 @@ function isViewTableType(tableType?: string): boolean {
return tableType?.toUpperCase().includes("VIEW") === true;
}
function isKnownOracleBaseTableType(tableType?: string): boolean {
return tableType?.trim().toUpperCase() === "TABLE";
}
export function isTdengineStableTableType(tableType?: string): boolean {
const normalized = tableType?.trim().toUpperCase();
return normalized === "STABLE" || normalized === "SUPER TABLE" || normalized === "SUPERTABLE";
@@ -19,7 +23,8 @@ export function editablePrimaryKeys(databaseType: DatabaseType | undefined, colu
if (isViewTableType(tableType)) return primaryKeys;
if (databaseType === "tdengine" && primaryKeys.length > 0 && isTdengineStableTableType(tableType)) return [DBX_TDENGINE_TBNAME_COLUMN, ...primaryKeys];
const syntheticKey = getDatabaseCapability(databaseType).syntheticKey;
if ((syntheticKey === "oracle-rowid" || syntheticKey === "xugu-rowid") && primaryKeys.length === 0) return [DBX_ROWID_COLUMN];
if (syntheticKey === "oracle-rowid" && primaryKeys.length === 0 && isKnownOracleBaseTableType(tableType)) return [DBX_ROWID_COLUMN];
if (syntheticKey === "xugu-rowid" && primaryKeys.length === 0) return [DBX_ROWID_COLUMN];
if (syntheticKey === "neo4j-element-id" && primaryKeys.length === 0) return [DBX_NEO4J_ELEMENT_ID_COLUMN];
return primaryKeys;
}
@@ -93,7 +98,9 @@ export function hiveTablePropertiesIndicateTransactional(result: { rows: readonl
export function usesSyntheticRowIdKey(databaseType: DatabaseType | undefined, primaryKeys: string[], tableType?: string): boolean {
if (isViewTableType(tableType)) return false;
const syntheticKey = getDatabaseCapability(databaseType).syntheticKey;
return primaryKeys.length === 1 && (((syntheticKey === "oracle-rowid" || syntheticKey === "xugu-rowid") && primaryKeys[0].toUpperCase() === DBX_ROWID_COLUMN) || (syntheticKey === "neo4j-element-id" && primaryKeys[0] === DBX_NEO4J_ELEMENT_ID_COLUMN));
if (primaryKeys.length !== 1) return false;
if (syntheticKey === "oracle-rowid" || syntheticKey === "xugu-rowid") return primaryKeys[0].toUpperCase() === DBX_ROWID_COLUMN;
return syntheticKey === "neo4j-element-id" && primaryKeys[0] === DBX_NEO4J_ELEMENT_ID_COLUMN;
}
/**
@@ -103,6 +110,7 @@ export function usesSyntheticRowIdKey(databaseType: DatabaseType | undefined, pr
*/
export function shouldIncludeSyntheticRowId(databaseType: DatabaseType | undefined, primaryKeys: string[], tableType?: string): boolean {
if (isViewTableType(tableType)) return false;
if (getDatabaseCapability(databaseType).syntheticKey === "oracle-rowid" && !isKnownOracleBaseTableType(tableType)) return false;
if (usesSyntheticRowIdKey(databaseType, primaryKeys, tableType)) return true;
return databaseType === "xugu" && primaryKeys.length === 0;
}