fix(oracle): select schema after connection switch
This commit is contained in:
1 parent
15972b222b
commit
b53f700dbe
4 files changed
+36
-2
No files matched your search
@@ -44,6 +44,7 @@ import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
|
||||
import { findTreeNodeById, resolveNewQueryTarget, resolveNewQueryInitialSql } from "@/lib/sql/newQueryContext";
|
||||
import { sqlObjectNavigationSourceKind, sqlObjectNavigationTableType, type SqlObjectNavigationTarget } from "@/lib/sql/sqlNavigation";
|
||||
import { buildExecutableObjectSourceStatements, executeObjectSourceSave } from "@/lib/table/objectSourceEditor";
|
||||
import { schemaAfterConnectionSwitch } from "@/lib/schema/connectionSchemaInitialization";
|
||||
import { resolveExecutableSql, resolveExecutableSqlWithBackend, type SqlExecutionSnapshot } from "@/lib/sql/sqlExecutionTarget";
|
||||
import { uuid } from "@/lib/common/utils";
|
||||
import { isMacOS, isWindows } from "@/lib/backend/platform";
|
||||
@@ -1482,7 +1483,19 @@ async function changeActiveConnection(connectionId: string) {
|
||||
try {
|
||||
await connectionStore.ensureConnected(connectionId);
|
||||
const options = await getDatabaseOptions(connectionId);
|
||||
queryStore.updateDatabase(tab.id, resolveDefaultDatabase(connection, options));
|
||||
const database = resolveDefaultDatabase(connection, options);
|
||||
queryStore.updateDatabase(tab.id, database);
|
||||
if (connection.db_type === "oracle") {
|
||||
try {
|
||||
// Oracle returns the session's current schema first; preserve that order before toolbar sorting.
|
||||
const schema = schemaAfterConnectionSwitch(connection.db_type, await api.listSchemas(connectionId, database));
|
||||
if (schema && activeTab.value?.id === tab.id && activeTab.value.connectionId === connectionId) {
|
||||
queryStore.updateSchema(tab.id, schema);
|
||||
}
|
||||
} catch {
|
||||
// Schema metadata failure must not turn a successful connection switch into a connection error.
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
toast(
|
||||
t("connection.connectFailed", {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { schemaAfterConnectionSwitch } from "@/lib/schema/connectionSchemaInitialization";
|
||||
|
||||
describe("schemaAfterConnectionSwitch", () => {
|
||||
it("selects the current Oracle schema from the raw ordered result", () => {
|
||||
expect(schemaAfterConnectionSwitch("oracle", ["CONNECTED_USER", "APP", "SYSTEM"])).toBe("CONNECTED_USER");
|
||||
});
|
||||
|
||||
it("does not initialize schemas for non-Oracle connections", () => {
|
||||
expect(schemaAfterConnectionSwitch("postgres", ["public", "archive"])).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
|
||||
export function schemaAfterConnectionSwitch(databaseType: DatabaseType | undefined, orderedSchemaNames: string[]): string | undefined {
|
||||
if (databaseType !== "oracle") return undefined;
|
||||
return orderedSchemaNames[0];
|
||||
}
|
||||
@@ -155,7 +155,10 @@ describe("queryStore multi-statement errors", () => {
|
||||
|
||||
store.updateSchema(tabId, undefined);
|
||||
|
||||
expect(store.tabs.find((tab) => tab.id === tabId)?.completionContextVersion).toBe(1);
|
||||
expect(store.tabs.find((tab) => tab.id === tabId)).toMatchObject({
|
||||
schema: undefined,
|
||||
completionContextVersion: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves the selected statement's absolute editor range", async () => {
|
||||
|
||||
Reference in new issue
Block a user