fix(saved-sql): scope SQL names and guard target persistence

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-17 22:35:56 +08:00
1 parent d1a2d51351
commit 58c1435d55
8 files changed
+715 -73

No files matched your search

+6
View File
@@ -2743,18 +2743,23 @@ async function changeActiveConnection(tabId: string, connectionId: string) {
if (!connection) return;
const initialDatabase = resolveDefaultDatabase(connection, []);
queryStore.updateConnection(tab.id, connectionId, initialDatabase);
let isCurrentTarget = queryStore.createExecutionTargetGuard(tab.id);
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database: initialDatabase, catalog: undefined, schema: undefined });
connectionStore.activeConnectionId = connectionId;
try {
await connectionStore.ensureConnected(connectionId);
if (!isCurrentTarget()) return;
const options = await getDatabaseOptions(connectionId);
if (!isCurrentTarget()) return;
const database = resolveDefaultDatabase(connection, options);
queryStore.updateDatabase(tab.id, database);
isCurrentTarget = queryStore.createExecutionTargetGuard(tab.id);
if (tab.externalSqlPath) rememberExternalSqlFileTarget(tab.externalSqlPath, { connectionId, database, catalog: undefined, schema: undefined });
if (connection.default_schema || connection.db_type === "oracle") {
try {
// A configured default wins. Otherwise Oracle returns the session's current schema first.
const orderedSchemas = connection.default_schema ? [] : await api.listSchemas(connectionId, database);
if (!isCurrentTarget()) return;
const schema = schemaAfterConnectionSwitch(connection.db_type, orderedSchemas, connection.default_schema);
const latestTab = queryStore.tabs.find((candidate) => candidate.id === tab.id);
if (schema && latestTab && latestTab.connectionId === connectionId) {
@@ -2766,6 +2771,7 @@ async function changeActiveConnection(tabId: string, connectionId: string) {
}
}
} catch (e: any) {
if (!isCurrentTarget()) return;
toast(
t("connection.connectFailed", {
message: translateBackendError(t, e),