fix(oracle): restore alias completion and DIP visibility
This commit is contained in:
18 files changed
+394
-61
No files matched your search
@@ -232,6 +232,95 @@ describe("connectionStore completion assistant", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("lets Oracle resolve CURRENT_SCHEMA for unqualified column completion", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
const getColumns = vi.fn().mockResolvedValue([{ name: "REPORT_ID", data_type: "NUMBER", is_nullable: false, column_default: null, is_primary_key: true, extra: null, comment: null }]);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
getColumns,
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [oracleConnection()];
|
||||
store.connectedIds.add("oracle-1");
|
||||
|
||||
const columns = await store.listCompletionColumns("oracle-1", "ORCL", "ORDERS", undefined, { clientSessionId: "tab-a", version: 0 });
|
||||
|
||||
expect(completionAssistantSearch).not.toHaveBeenCalled();
|
||||
expect(getColumns).toHaveBeenCalledWith("oracle-1", "ORCL", "", "ORDERS", undefined, "tab-a");
|
||||
expect(columns).toEqual([expect.objectContaining({ name: "REPORT_ID", table: "ORDERS", schema: undefined, dataType: "NUMBER" })]);
|
||||
expect(store.lookupLocalCompletionColumns("oracle-1", "ORCL", "ORDERS")).toEqual([]);
|
||||
});
|
||||
|
||||
it("isolates Oracle CURRENT_SCHEMA column caches by tab and context version", async () => {
|
||||
const completionAssistantSearch = vi.fn();
|
||||
const getColumns = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce([{ name: "APP_ID", data_type: "NUMBER", is_nullable: false }])
|
||||
.mockResolvedValueOnce([{ name: "REPORT_ID", data_type: "NUMBER", is_nullable: false }])
|
||||
.mockResolvedValueOnce([{ name: "SYSTEM_ID", data_type: "NUMBER", is_nullable: false }]);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
getColumns,
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [oracleConnection()];
|
||||
store.connectedIds.add("oracle-1");
|
||||
|
||||
const app = await store.listCompletionColumns("oracle-1", "ORCL", "SHARED_TABLE", undefined, { clientSessionId: "tab-a", version: 0 });
|
||||
const cachedApp = await store.listCompletionColumns("oracle-1", "ORCL", "SHARED_TABLE", undefined, { clientSessionId: "tab-a", version: 0 });
|
||||
const reporting = await store.listCompletionColumns("oracle-1", "ORCL", "SHARED_TABLE", undefined, { clientSessionId: "tab-a", version: 1 });
|
||||
const independentTab = await store.listCompletionColumns("oracle-1", "ORCL", "SHARED_TABLE", undefined, { clientSessionId: "tab-b", version: 0 });
|
||||
|
||||
expect(app.map((column) => column.name)).toEqual(["APP_ID"]);
|
||||
expect(cachedApp.map((column) => column.name)).toEqual(["APP_ID"]);
|
||||
expect(reporting.map((column) => column.name)).toEqual(["REPORT_ID"]);
|
||||
expect(independentTab.map((column) => column.name)).toEqual(["SYSTEM_ID"]);
|
||||
expect(getColumns).toHaveBeenCalledTimes(3);
|
||||
expect(getColumns.mock.calls.map((call) => call[5])).toEqual(["tab-a", "tab-a", "tab-b"]);
|
||||
expect(completionAssistantSearch).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps explicit Oracle schema completion on the shared assistant path", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "EXPLICIT_ID", kind: "column", schema: "REPORTING", parent_schema: "REPORTING", parent_name: "SHARED_TABLE", data_type: "NUMBER" }],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
const getColumns = vi.fn();
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
getColumns,
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [oracleConnection()];
|
||||
store.connectedIds.add("oracle-1");
|
||||
|
||||
const columns = await store.listCompletionColumns("oracle-1", "ORCL", "SHARED_TABLE", "REPORTING", { clientSessionId: "tab-a", version: 2 });
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenCalledWith(expect.objectContaining({ schema: "REPORTING", parent_schema: "REPORTING", parent_name: "SHARED_TABLE" }));
|
||||
expect(getColumns).not.toHaveBeenCalled();
|
||||
expect(columns).toEqual([expect.objectContaining({ name: "EXPLICIT_ID", schema: "REPORTING" })]);
|
||||
});
|
||||
|
||||
it("maps Oracle package members without scanning every schema", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "CALCULATE_BONUS", kind: "function", schema: "HR", parent_schema: "HR", parent_name: "PAYROLL", data_type: "FUNCTION" }],
|
||||
|
||||
@@ -83,6 +83,51 @@ describe("queryStore multi-statement errors", () => {
|
||||
expect(tab.result?.columns).toEqual(["Error"]);
|
||||
});
|
||||
|
||||
it("invalidates only the executing Oracle tab after successful CURRENT_SCHEMA changes", async () => {
|
||||
mocks.getConnectionConfig.mockReturnValue({
|
||||
id: "oracle-1",
|
||||
name: "Oracle",
|
||||
db_type: "oracle",
|
||||
database: "ORCL",
|
||||
query_timeout_secs: 30,
|
||||
});
|
||||
mocks.executeMulti
|
||||
.mockResolvedValueOnce([{ columns: [], rows: [], affected_rows: 0, execution_time_ms: 1 }])
|
||||
.mockResolvedValueOnce([{ columns: ["Error"], rows: [["schema missing"]], affected_rows: 0, execution_time_ms: 1, execution_error: true }])
|
||||
.mockResolvedValueOnce([{ columns: [], rows: [], affected_rows: 0, execution_time_ms: 1 }]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabA = store.createTab("oracle-1", "ORCL", "Tab A");
|
||||
const tabB = store.createTab("oracle-1", "ORCL", "Tab B");
|
||||
|
||||
await store.executeTabSql(tabA, "ALTER SESSION SET CURRENT_SCHEMA = REPORTING");
|
||||
expect(store.tabs.find((tab) => tab.id === tabA)?.completionContextVersion).toBe(1);
|
||||
expect(store.tabs.find((tab) => tab.id === tabB)?.completionContextVersion).toBeUndefined();
|
||||
|
||||
await store.executeTabSql(tabA, "/* retry */ ALTER SESSION SET CURRENT_SCHEMA = MISSING");
|
||||
expect(store.tabs.find((tab) => tab.id === tabA)?.completionContextVersion).toBe(1);
|
||||
|
||||
await store.executeTabSql(tabA, "-- switch back\nALTER SESSION SET CURRENT_SCHEMA = APP");
|
||||
expect(store.tabs.find((tab) => tab.id === tabA)?.completionContextVersion).toBe(2);
|
||||
expect(mocks.executeMulti.mock.calls.map((call) => call[5]?.clientSessionId)).toEqual([tabA, tabA, tabA]);
|
||||
});
|
||||
|
||||
it("invalidates Oracle completion metadata when clearing a tab schema resets its session", async () => {
|
||||
mocks.getConnectionConfig.mockReturnValue({
|
||||
id: "oracle-1",
|
||||
name: "Oracle",
|
||||
db_type: "oracle",
|
||||
database: "ORCL",
|
||||
});
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("oracle-1", "ORCL", "Oracle", "query", "REPORTING");
|
||||
|
||||
store.updateSchema(tabId, undefined);
|
||||
|
||||
expect(store.tabs.find((tab) => tab.id === tabId)?.completionContextVersion).toBe(1);
|
||||
});
|
||||
|
||||
it("preserves the selected statement's absolute editor range", async () => {
|
||||
mocks.executeMulti.mockResolvedValue([{ columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 }]);
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
|
||||
@@ -2281,7 +2281,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
} else if (config && connectionUsesVisibleSchemaFilter(config)) {
|
||||
const schemaFilterConfig = config;
|
||||
const effectiveDb = schemaFilterConfig.database || "";
|
||||
const cacheKey = schemaCacheKey(connectionId, effectiveDb, "schemas");
|
||||
const cacheKey = schemaCacheKey(connectionId, effectiveDb, config.db_type === "oracle" ? "schemas-v2" : "schemas");
|
||||
if (!options?.force) {
|
||||
const cached = await loadPersistedTreeChildren(node, cacheKey);
|
||||
if (cached.hit) {
|
||||
@@ -4781,39 +4781,45 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return deduped;
|
||||
}
|
||||
|
||||
async function listCompletionColumns(connectionId: string, database: string, table: string, schema?: string): Promise<SqlCompletionColumn[]> {
|
||||
if (isSchemaAwareDatabase(connectionId) && !connectionUsesDatabaseObjectTreeMode(getConfig(connectionId)) && !schema) {
|
||||
async function listCompletionColumns(connectionId: string, database: string, table: string, schema?: string, context?: { clientSessionId?: string; version?: number }): Promise<SqlCompletionColumn[]> {
|
||||
const config = getConfig(connectionId);
|
||||
const completionSchema = schema?.trim() || undefined;
|
||||
const usesOracleCurrentSchema = config?.db_type === "oracle" && !completionSchema;
|
||||
if (isSchemaAwareDatabase(connectionId) && !connectionUsesDatabaseObjectTreeMode(config) && !completionSchema && !usesOracleCurrentSchema) {
|
||||
return [];
|
||||
}
|
||||
const cacheKey = `${connectionId}:${database}:${schema || ""}:${table}`;
|
||||
const sessionCacheScope = usesOracleCurrentSchema && context?.clientSessionId ? `:${context.clientSessionId}:${context.version ?? 0}` : "";
|
||||
const cacheKey = `${connectionId}:${database}:${schema || ""}:${table}${sessionCacheScope}`;
|
||||
if (!completionColumnsCache.value[cacheKey]) {
|
||||
await withCompletionInFlight(
|
||||
`${cacheKey}:columns`,
|
||||
async () => {
|
||||
await ensureConnected(connectionId);
|
||||
try {
|
||||
const assistantColumns = await listCompletionAssistantColumns(connectionId, database, table, schema);
|
||||
if (assistantColumns.length > 0) {
|
||||
completionColumnsCache.value[cacheKey] = assistantColumns.map((column) => ({
|
||||
name: column.name,
|
||||
data_type: column.dataType ?? "",
|
||||
is_nullable: column.isNullable ?? true,
|
||||
column_default: null,
|
||||
is_primary_key: false,
|
||||
extra: null,
|
||||
comment: column.comment ?? null,
|
||||
numeric_precision: null,
|
||||
numeric_scale: null,
|
||||
character_maximum_length: null,
|
||||
}));
|
||||
evictOldestCacheEntries(completionColumnsCache.value, COMPLETION_CACHE_MAX);
|
||||
return;
|
||||
if (!usesOracleCurrentSchema) {
|
||||
try {
|
||||
const assistantColumns = await listCompletionAssistantColumns(connectionId, database, table, completionSchema);
|
||||
if (assistantColumns.length > 0) {
|
||||
completionColumnsCache.value[cacheKey] = assistantColumns.map((column) => ({
|
||||
name: column.name,
|
||||
data_type: column.dataType ?? "",
|
||||
is_nullable: column.isNullable ?? true,
|
||||
column_default: null,
|
||||
is_primary_key: false,
|
||||
extra: null,
|
||||
comment: column.comment ?? null,
|
||||
numeric_precision: null,
|
||||
numeric_scale: null,
|
||||
character_maximum_length: null,
|
||||
}));
|
||||
evictOldestCacheEntries(completionColumnsCache.value, COMPLETION_CACHE_MAX);
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Fall back to the existing metadata path below.
|
||||
}
|
||||
} catch {
|
||||
// Fall back to the existing metadata path below.
|
||||
}
|
||||
const querySchema = metadataQuerySchema(connectionId, database, schema);
|
||||
completionColumnsCache.value[cacheKey] = await api.getColumns(connectionId, database, querySchema, table);
|
||||
const querySchema = usesOracleCurrentSchema ? "" : metadataQuerySchema(connectionId, database, completionSchema);
|
||||
completionColumnsCache.value[cacheKey] = await api.getColumns(connectionId, database, querySchema, table, undefined, usesOracleCurrentSchema ? context?.clientSessionId : undefined);
|
||||
evictOldestCacheEntries(completionColumnsCache.value, COMPLETION_CACHE_MAX);
|
||||
},
|
||||
{ scope: completionLimiterScope(connectionId, database), kind: "columns" },
|
||||
@@ -4823,12 +4829,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const columns = completionColumnsCache.value[cacheKey].map((column) => ({
|
||||
name: column.name,
|
||||
table,
|
||||
schema,
|
||||
schema: completionSchema,
|
||||
dataType: column.data_type,
|
||||
isNullable: column.is_nullable,
|
||||
comment: column.comment,
|
||||
}));
|
||||
indexCompletionColumns(connectionId, database, table, schema, columns);
|
||||
if (!usesOracleCurrentSchema) indexCompletionColumns(connectionId, database, table, schema, columns);
|
||||
return columns;
|
||||
}
|
||||
|
||||
@@ -4874,8 +4880,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
return listCompletionDatabases(connectionId);
|
||||
}
|
||||
|
||||
function refreshCompletionColumns(connectionId: string, database: string, table: string, schema?: string): Promise<SqlCompletionColumn[]> {
|
||||
return listCompletionColumns(connectionId, database, table, schema);
|
||||
function refreshCompletionColumns(connectionId: string, database: string, table: string, schema?: string, context?: { clientSessionId?: string; version?: number }): Promise<SqlCompletionColumn[]> {
|
||||
return listCompletionColumns(connectionId, database, table, schema, context);
|
||||
}
|
||||
|
||||
function refreshCompletionForeignKeys(connectionId: string, database: string, table: string, schema?: string): Promise<SqlCompletionForeignKey[]> {
|
||||
|
||||
@@ -186,6 +186,25 @@ function annotateQueryResultSources(results: QueryResult[], sql: string, databas
|
||||
return results;
|
||||
}
|
||||
|
||||
function isOracleCurrentSchemaStatement(statement: string | undefined): boolean {
|
||||
let remaining = statement?.trimStart() ?? "";
|
||||
while (remaining) {
|
||||
if (remaining.startsWith("--")) {
|
||||
const newline = remaining.indexOf("\n");
|
||||
remaining = newline < 0 ? "" : remaining.slice(newline + 1).trimStart();
|
||||
continue;
|
||||
}
|
||||
if (remaining.startsWith("/*")) {
|
||||
const end = remaining.indexOf("*/", 2);
|
||||
if (end < 0) return false;
|
||||
remaining = remaining.slice(end + 2).trimStart();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return /^ALTER\s+SESSION\s+SET\s+CURRENT_SCHEMA\s*=/i.test(remaining);
|
||||
}
|
||||
|
||||
function annotateQueryResultSource(result: QueryResult, sourceStatement: string, database?: string, databaseType?: DatabaseType, sourceRange?: { from: number; to: number }): QueryResult {
|
||||
result.sourceStatement = sourceStatement;
|
||||
if (sourceRange) {
|
||||
@@ -514,6 +533,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
|
||||
function queueTabSessionReset(tab: QueryTab) {
|
||||
tab.completionContextVersion = (tab.completionContextVersion ?? 0) + 1;
|
||||
const previousReset = pendingTabSessionResets.get(tab.id);
|
||||
const reset = (async () => {
|
||||
if (previousReset) await previousReset;
|
||||
@@ -3412,6 +3432,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
executionPromise = api.executeMulti(tab.connectionId, executionDatabase, sqlToExecute, executionSchema, executionId, executionOptions);
|
||||
}
|
||||
const results = annotateQueryResultSources(markQueryResultsRowsRaw(await withFrontendQueryTimeout(executionPromise, frontendTimeoutSecs, t("editor.queryTimeoutError", { seconds: frontendTimeoutSecs }))), queryBaseSql, sourceLabelDatabase, effectiveDbType, options?.sourceOffset);
|
||||
const successfulOracleSchemaChanges = effectiveDbType === "oracle" ? results.filter((result) => result.execution_error !== true && isOracleCurrentSchemaStatement(result.sourceStatement)).length : 0;
|
||||
if (hiddenPrimaryKeys.length > 0 && results.length === 1) {
|
||||
const hiddenIndexes = hiddenResultColumnIndexes(results[0]!.columns, hiddenPrimaryKeys);
|
||||
if (hiddenIndexes.length > 0) results[0]!.hidden_column_indexes = hiddenIndexes;
|
||||
@@ -3428,6 +3449,9 @@ export const useQueryStore = defineStore("query", () => {
|
||||
});
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current?.executionId === executionId) {
|
||||
if (successfulOracleSchemaChanges > 0) {
|
||||
current.completionContextVersion = (current.completionContextVersion ?? 0) + successfulOracleSchemaChanges;
|
||||
}
|
||||
const activeGroupIndex = current.activeResultIndex;
|
||||
const activeGroupResults = current.results;
|
||||
const shouldAppendResult = !!options?.appendResult && !!current.result;
|
||||
|
||||
Reference in new issue
Block a user