Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(editor): prompt connection selection when executing SQL without a connection (#12858)

lxk95518320eea6865
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 36e64120e5..2c158f8ec2 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -1036,6 +1036,8 @@ const blockDangerousRedisCommands = computed({
});
const databaseRequiredSignal = ref(0);
const databaseRequiredTabId = ref<string | null>(null);
+const connectionRequiredSignal = ref(0);
+const connectionRequiredTabId = ref<string | null>(null);
const pendingToolbarExecutionSnapshot = ref<SqlExecutionSnapshot & { tabId?: string }>();
const sqlExecutionDangerStore = useSqlExecutionDangerStore();
const productionSafetyStore = useProductionSafetyStore();
@@ -1048,6 +1050,14 @@ function promptActiveDatabaseSelection(tabId?: string) {
toast(t("editor.selectDatabaseRequired"), 2500);
}
+function promptActiveConnectionSelection(tabId?: string) {
+ const tab = tabId ? queryStore.tabs.find((candidate) => candidate.id === tabId) : activeTab.value;
+ if (!tab) return;
+ connectionRequiredTabId.value = tab.id;
+ connectionRequiredSignal.value += 1;
+ toast(t("editor.selectConnectionRequired"), 2500);
+}
+
const {
dangerSql,
showDangerDialog,
@@ -1076,6 +1086,7 @@ const {
activeOutputView,
blockDangerousRedisCommands,
onMissingDatabase: promptActiveDatabaseSelection,
+ onMissingConnection: promptActiveConnectionSelection,
requestDangerConfirmation: (request) => sqlExecutionDangerStore.requestConfirmation(request),
onExecutionStarted: (editorViewportRequestId) => contentAreaRef.value?.acceptQueryEditorExecutionViewport(editorViewportRequestId),
onExecutionCancelled: (editorViewportRequestId) => contentAreaRef.value?.cancelQueryEditorExecutionViewport(editorViewportRequestId),
@@ -1158,6 +1169,7 @@ provide(EDITOR_TOOLBAR_ACTIONS, {
explainMode,
blockDangerousRedisCommands,
databaseRequiredSignalFor: (tabId: string) => (databaseRequiredTabId.value === tabId ? databaseRequiredSignal.value : 0),
+ connectionRequiredSignalFor: (tabId: string) => (connectionRequiredTabId.value === tabId ? connectionRequiredSignal.value : 0),
captureExecutionSnapshot: captureActiveEditorExecutionSnapshot,
toolbarExecute: requestActiveEditorExecute,
toolbarExecuteInNewResultTab: requestActiveEditorExecuteInNewResultTab,
@@ -3571,6 +3583,9 @@ async function changeActiveConnection(tabId: string, connectionId: string) {
if (!tab) return;
const connection = connectionStore.getConfig(connectionId);
if (!connection) return;
+ if (connectionRequiredTabId.value === tab.id) {
+ connectionRequiredTabId.value = null;
+ }
const initialDatabase = resolveDefaultDatabase(connection, []);
queryStore.updateConnection(tab.id, connectionId, initialDatabase);
let isCurrentTarget = queryStore.createExecutionTargetGuard(tab.id);
diff --git a/apps/desktop/src/components/layout/EditorGroup.vue b/apps/desktop/src/components/layout/EditorGroup.vue
index ee10b935ac..22439fdefe 100644
--- a/apps/desktop/src/components/layout/EditorGroup.vue
+++ b/apps/desktop/src/components/layout/EditorGroup.vue
@@ -217,6 +217,7 @@ const groupExecutableSql = computed(() => {
:block-dangerous-redis-commands="toolbar.blockDangerousRedisCommands.value"
:sql-keyword-case="settingsStore.editorSettings.sqlFormatter.keywordCase"
:database-required-signal="toolbar.databaseRequiredSignalFor(activeTab.id)"
+ :connection-required-signal="toolbar.connectionRequiredSignalFor(activeTab.id)"
:auto-commit="activeTab.autoCommit ?? true"
:txn-session-id="activeTab.txnSessionId"
:txn-auto-rolled-back="activeTab.txnAutoRolledBack"
diff --git a/apps/desktop/src/components/layout/EditorToolbar.vue b/apps/desktop/src/components/layout/EditorToolbar.vue
index f782a980c7..f478c57d3f 100644
--- a/apps/desktop/src/components/layout/EditorToolbar.vue
+++ b/apps/desktop/src/components/layout/EditorToolbar.vue
@@ -71,6 +71,8 @@ const props = defineProps<{
blockDangerousRedisCommands?: boolean;
sqlKeywordCase: "preserve" | "upper" | "lower";
databaseRequiredSignal?: number;
+ /** When non-zero, highlights and opens the connection picker so the user selects a connection. */
+ connectionRequiredSignal?: number;
autoCommit?: boolean;
txnSessionId?: string;
txnAutoRolledBack?: boolean;
@@ -436,10 +438,28 @@ watch(
},
);
+const connectionRequiredVisible = ref(false);
+
+watch(
+ () => props.connectionRequiredSignal,
+ (signal) => {
+ if (!signal) return;
+ connectionRequiredVisible.value = false;
+ requestAnimationFrame(() => {
+ connectionRequiredVisible.value = true;
+ connectionPickerRef.value?.openDropdown();
+ });
+ },
+);
+
watch(activeDatabaseValue, (database) => {
if (database) databaseRequiredVisible.value = false;
});
+watch(activeConnectionValue, (connectionId) => {
+ if (connectionId) connectionRequiredVisible.value = false;
+});
+
/**
* 用户在侧栏显式关闭过、且还没重新连上的连接。
*
@@ -951,7 +971,7 @@ defineExpose({
</div>
</div>
<div class="flex shrink-0 items-center gap-2">
- <div class="flex shrink-0 items-center gap-1">
+ <div class="flex shrink-0 items-center gap-1" :class="{ 'connection-required-prompt': connectionRequiredVisible }">
<span v-if="activeConnection?.color" class="h-4 w-1 rounded-full shrink-0" :style="{ backgroundColor: activeConnection.color }" />
<ConnectionTreeSelect
ref="connectionPickerRef"
@@ -1170,4 +1190,15 @@ defineExpose({
transform: translateX(3px);
}
}
+
+.connection-required-prompt {
+ color: var(--destructive);
+ animation: database-required-shake 420ms ease;
+}
+
+.connection-required-prompt :deep(button) {
+ color: var(--destructive);
+ border-color: color-mix(in oklch, var(--destructive) 55%, transparent);
+ background: color-mix(in oklch, var(--destructive) 10%, transparent);
+}
</style>
diff --git a/apps/desktop/src/components/layout/editorToolbarActions.ts b/apps/desktop/src/components/layout/editorToolbarActions.ts
index 1e4748e1d7..6bcaafefac 100644
--- a/apps/desktop/src/components/layout/editorToolbarActions.ts
+++ b/apps/desktop/src/components/layout/editorToolbarActions.ts
@@ -27,6 +27,8 @@ export interface EditorToolbarActions {
blockDangerousRedisCommands: Ref<boolean>;
/** Highlights the database selector of the tab that needs a database choice. */
databaseRequiredSignalFor(tabId: string): number;
+ /** Highlights and opens the connection selector of the tab that needs a connection choice. */
+ connectionRequiredSignalFor(tabId: string): number;
/** Captures the acting editor's execution snapshot before a toolbar click. */
captureExecutionSnapshot(tabId: string): void;
toolbarExecute(source: "pointer" | "keyboard", tabId: string): void;
@@ -80,6 +82,7 @@ export function createNoopEditorToolbarActions(): EditorToolbarActions {
explainMode: mode,
blockDangerousRedisCommands: flag,
databaseRequiredSignalFor: () => 0,
+ connectionRequiredSignalFor: () => 0,
captureExecutionSnapshot: noop,
toolbarExecute: noop,
toolbarExecuteInNewResultTab: noop,
diff --git a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts
index fdcaf86e23..dbc61e1fd3 100644
--- a/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts
+++ b/apps/desktop/src/composables/__tests__/useSqlExecution.spec.ts
@@ -1,7 +1,7 @@
import { computed, nextTick, ref } from "vue";
import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it, vi } from "vitest";
-import { isDangerousSql, requiresDatabaseSelection, snapshotResultForMerge, supportsSqlTemplateParameters, useSqlExecution } from "../useSqlExecution";
+import { isDangerousSql, requiresConnectionSelection, requiresDatabaseSelection, snapshotResultForMerge, supportsSqlTemplateParameters, useSqlExecution } from "../useSqlExecution";
import { useConnectionStore } from "@/stores/connectionStore";
import { useHistoryStore } from "@/stores/historyStore";
import { useQueryStore } from "@/stores/queryStore";
@@ -127,6 +127,29 @@ describe("requiresDatabaseSelection", () => {
});
});
+describe("requiresConnectionSelection", () => {
+ beforeEach(() => {
+ installLocalStorage();
+ setActivePinia(createPinia());
+ });
+
+ it("requires a connection for a query tab without one", () => {
+ const tab = queryTab();
+ tab.connectionId = "";
+ expect(requiresConnectionSelection(tab, undefined)).toBe(true);
+ });
+
+ it("does not require a connection when one is resolved", () => {
+ expect(requiresConnectionSelection(queryTab(), connection("mysql"))).toBe(false);
+ });
+
+ it("never requires a connection for non-query tabs", () => {
+ const tab = queryTab();
+ tab.mode = "databases";
+ expect(requiresConnectionSelection(tab, undefined)).toBe(false);
+ });
+});
+
describe("supportsSqlTemplateParameters", () => {
it("disables SQL parameter prompts for Meilisearch input", () => {
expect(supportsSqlTemplateParameters(connection("meilisearch"), "GET /indexes/:uid")).toBe(false);
@@ -181,6 +204,30 @@ describe("useSqlExecution", () => {
expect(executeCurrentSql).toHaveBeenCalledWith(sql, { tabId: "tab-1" });
});
+ it("prompts for a connection instead of executing when no connection is selected", async () => {
+ const sql = "SELECT 1";
+ const activeTab = ref<QueryTab | undefined>({ ...queryTab(), connectionId: "", sql });
+ const activeConnection = ref<ConnectionConfig | undefined>(undefined);
+ const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
+ const queryStore = useQueryStore();
+ const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockResolvedValue(undefined);
+ vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
+ const onMissingConnection = vi.fn();
+
+ const execution = useSqlExecution({
+ activeTab: computed(() => activeTab.value),
+ activeConnection: computed(() => activeConnection.value),
+ executableSql: computed(() => sql),
+ activeOutputView,
+ onMissingConnection,
+ });
+
+ await execution.tryExecute();
+
+ expect(onMissingConnection).toHaveBeenCalledWith("tab-1");
+ expect(executeCurrentSql).not.toHaveBeenCalled();
+ });
+
it("invalidates object metadata after successful connection-level DDL", async () => {
const sql = "CREATE DATABASE app_db";
const activeTab = ref<QueryTab | undefined>({ ...queryTab(), sql });
diff --git a/apps/desktop/src/composables/useSqlExecution.ts b/apps/desktop/src/composables/useSqlExecution.ts
index 2f4e127bfd..a14ab9b09d 100644
--- a/apps/desktop/src/composables/useSqlExecution.ts
+++ b/apps/desktop/src/composables/useSqlExecution.ts
@@ -168,6 +168,7 @@ export function useSqlExecution(deps: {
resolveExecutableSql?: (snapshot?: SqlExecutionSnapshot, tab?: QueryTab) => Promise<string>;
activeOutputView: Ref<"result" | "graph" | "summary" | "explain" | "chart" | "messages" | "profile">;
blockDangerousRedisCommands?: Ref<boolean>;
+ onMissingConnection?: (tabId?: string) => void;
onMissingDatabase?: (tabId?: string) => void;
requestDangerConfirmation?: (request: SqlExecutionDangerRequest) => Promise<boolean>;
onExecutionStarted?: (editorViewportRequestId: number) => void;
@@ -234,7 +235,11 @@ export function useSqlExecution(deps: {
function resolveExecutionConnection(tabId: string | undefined): ConnectionConfig | undefined {
const tab = resolveExecutionTab(tabId);
- return (tab ? connectionStore.getConfig(tab.connectionId) : undefined) ?? deps.activeConnection.value;
+ if (tab) {
+ if (!tab.connectionId) return undefined;
+ return connectionStore.getConfig(tab.connectionId) ?? (tab.connectionId === deps.activeConnection.value?.id ? deps.activeConnection.value : undefined);
+ }
+ return deps.activeConnection.value;
}
function captureExecutionContext(tabId?: string): SqlExecutionContext | undefined {
@@ -317,6 +322,11 @@ export function useSqlExecution(deps: {
cancelEditorViewportRequest(editorViewportRequestId);
return notStarted("busy", context.tabId);
}
+ if (requiresConnectionSelection(tab, context.connection)) {
+ deps.onMissingConnection?.(context.tabId);
+ cancelEditorViewportRequest(editorViewportRequestId);
+ return notStarted("no-connection", context.tabId);
+ }
if (requiresDatabaseSelection(tab, context.connection, sql)) {
deps.onMissingDatabase?.(context.tabId);
cancelEditorViewportRequest(editorViewportRequestId);
@@ -485,8 +495,13 @@ export function useSqlExecution(deps: {
cancelEditorViewportRequest(options.editorViewportRequestId);
return notStarted("no-tab", executionTabId);
}
- const executionConnection = connectionStore.getConfig(tab.connectionId) ?? deps.activeConnection.value;
+ const executionConnection = tab.connectionId ? (connectionStore.getConfig(tab.connectionId) ?? (tab.connectionId === deps.activeConnection.value?.id ? deps.activeConnection.value : undefined)) : undefined;
const executionDatabaseType = executionConnection?.db_type;
+ if (requiresConnectionSelection(tab, executionConnection)) {
+ deps.onMissingConnection?.(executionTabId);
+ cancelEditorViewportRequest(options.editorViewportRequestId);
+ return notStarted("no-connection", executionTabId);
+ }
if (requiresDatabaseSelection(tab, executionConnection, sql)) {
deps.onMissingDatabase?.(executionTabId);
cancelEditorViewportRequest(options.editorViewportRequestId);
@@ -627,6 +642,10 @@ export function useSqlExecution(deps: {
if (!(await ensureReadOnlyWriteAccess({ connection, sql, source: t("production.sourceMultiDbSql") }))) {
return finish({ status: "skipped", errorMessage: t("dangerDialog.cancel") });
}
+ if (requiresConnectionSelection(executionTab, connection)) {
+ deps.onMissingConnection?.(executionTab.id);
+ return finish({ status: "failed", errorMessage: t("editor.selectConnectionRequired") });
+ }
if (requiresDatabaseSelection(executionTab, connection, sql)) {
return finish({ status: "failed", errorMessage: t("editor.selectDatabaseRequired") });
}
@@ -961,6 +980,14 @@ export function useSqlExecution(deps: {
return;
}
const { sql, sourceOffset } = await resolvedExecutableSql(sqlOverride, context);
+ const tab = resolveExecutionTab(context.tabId);
+ if (!tab) {
+ return;
+ }
+ if (requiresConnectionSelection(tab, context.connection)) {
+ deps.onMissingConnection?.(context.tabId);
+ return;
+ }
if (!sql.trim()) {
toast(t("explain.emptySql"));
return;
@@ -1109,6 +1136,11 @@ export function supportsSqlTemplateParameters(connection: Pick<ConnectionConfig,
return connection.db_type !== "redis" && connection.db_type !== "mongodb" && connection.db_type !== "victoriametrics" && connection.db_type !== "salesforce";
}
+export function requiresConnectionSelection(tab: QueryTab, connection: ConnectionConfig | undefined): boolean {
+ if (tab.mode !== "query") return false;
+ return !connection;
+}
+
export function requiresDatabaseSelection(tab: QueryTab, connection: ConnectionConfig | undefined, _sql = ""): boolean {
if (tab.mode !== "query") return false;
if (!connection) return false;
diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts
index 48c7667aa0..b67b935229 100644
--- a/apps/desktop/src/i18n/locales/az.ts
+++ b/apps/desktop/src/i18n/locales/az.ts
@@ -1461,6 +1461,7 @@ export default withEnglishFallback({
selectCatalog: "Kataloq seç",
searchCatalog: "Kataloqları axtar...",
selectDatabase: "Verilənlər bazası seç",
+ selectConnectionRequired: "Əvvəlcə əlaqə seçin",
selectDatabaseRequired: "Əvvəlcə verilənlər bazası seçin",
searchDatabase: "Verilənlər bazalarını axtar...",
selectSchema: "Sxem seç",
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 2d809c9f8e..09771ad531 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -2126,6 +2126,7 @@ export default {
discardAllChanges: "Discard all",
saveAllChanges: "Save all",
selectConnection: "Select connection",
+ selectConnectionRequired: "Select a connection first",
searchConnection: "Search connections...",
selectCatalog: "Select catalog",
searchCatalog: "Search catalogs...",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index b239f30e78..ae434038a4 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -1979,6 +1979,7 @@ export default withEnglishFallback({
selectCatalog: "Seleccionar catálogo",
searchCatalog: "Buscar catálogos...",
selectDatabase: "Seleccionar base de datos",
+ selectConnectionRequired: "Selecciona una conexión primero",
selectDatabaseRequired: "Selecciona una base de datos primero",
searchDatabase: "Buscar bases de datos...",
selectSchema: "Seleccionar esquema",
diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts
index 67b75d6fe1..fd18b1c611 100644
--- a/apps/desktop/src/i18n/locales/id.ts
+++ b/apps/desktop/src/i18n/locales/id.ts
@@ -1727,6 +1727,7 @@ export default withEnglishFallback({
selectCatalog: "Pilih katalog",
searchCatalog: "Cari katalog...",
selectDatabase: "Pilih database",
+ selectConnectionRequired: "Pilih koneksi terlebih dahulu",
selectDatabaseRequired: "Pilih database terlebih dahulu",
searchDatabase: "Cari database...",
selectSchema: "Pilih skema",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index dff9900a11..5431764f12 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -1888,6 +1888,7 @@ export default withEnglishFallback({
selectCatalog: "Seleziona catalogo",
searchCatalog: "Cerca cataloghi...",
selectDatabase: "Seleziona database",
+ selectConnectionRequired: "Seleziona prima una connessione",
selectDatabaseRequired: "Seleziona prima un database",
searchDatabase: "Cerca database...",
selectSchema: "Seleziona schema",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 2ef3b4afc1..7554e8deae 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -2082,6 +2082,7 @@ export default withEnglishFallback({
currentCommand: "Current command",
allCommands: "All commands",
},
+ selectConnectionRequired: "先に接続を選択してください",
selectDatabaseRequired: "先にデータベースを選択してください",
statementExecutionRunning: "{count} 件のステートメントを実行中",
statementExecutionSucceeded: "{count} 件のステートメントが成功しました",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index fdfc9b698b..3bcbf76f68 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -1812,6 +1812,7 @@ export default withEnglishFallback({
selectConnection: "연결 선택",
searchConnection: "연결 검색...",
selectDatabase: "데이터베이스 선택",
+ selectConnectionRequired: "먼저 연결을 선택하세요",
selectDatabaseRequired: "먼저 데이터베이스를 선택하세요",
searchDatabase: "데이터베이스 검색...",
selectSchema: "스키마 선택",
diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.ts
index 751de68550..72874274b0 100644
--- a/apps/desktop/src/i18n/locales/pl.ts
+++ b/apps/desktop/src/i18n/locales/pl.ts
@@ -1771,6 +1771,7 @@ export default withEnglishFallback({
selectCatalog: "Wybierz katalog",
searchCatalog: "Szukaj katalogów...",
selectDatabase: "Wybierz bazę danych",
+ selectConnectionRequired: "Najpierw wybierz połączenie",
selectDatabaseRequired: "Najpierw wybierz bazę danych",
searchDatabase: "Szukaj baz danych...",
selectSchema: "Wybierz schemat",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index fa55cce2c0..69e2fa8f9c 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -1889,6 +1889,7 @@ export default withEnglishFallback({
selectCatalog: "Selecionar catálogo",
searchCatalog: "Pesquisar catálogos...",
selectDatabase: "Selecionar banco de dados",
+ selectConnectionRequired: "Selecione uma conexão primeiro",
selectDatabaseRequired: "Selecione um banco de dados primeiro",
searchDatabase: "Pesquisar bancos de dados...",
selectSchema: "Selecionar schema",
diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts
index 5d265dfba8..3546ad5ec9 100644
--- a/apps/desktop/src/i18n/locales/ru.ts
+++ b/apps/desktop/src/i18n/locales/ru.ts
@@ -1892,6 +1892,7 @@ export default withEnglishFallback({
selectCatalog: "Выбрать каталог",
searchCatalog: "Поиск каталогов...",
selectDatabase: "Выбрать базу данных",
+ selectConnectionRequired: "Сначала выберите подключение",
selectDatabaseRequired: "Сначала выберите базу данных",
searchDatabase: "Поиск баз данных...",
selectSchema: "Выбрать схему",
diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.ts
index 8b3c56bdd4..6ca54fe6dd 100644
--- a/apps/desktop/src/i18n/locales/th.ts
+++ b/apps/desktop/src/i18n/locales/th.ts
@@ -2089,6 +2089,7 @@ export default withEnglishFallback({
selectCatalog: "เลือก Catalog",
searchCatalog: "ค้นหา Catalog...",
selectDatabase: "เลือกฐานข้อมูล",
+ selectConnectionRequired: "เลือกการเชื่อมต่อก่อน",
selectDatabaseRequired: "เลือกฐานข้อมูลก่อน",
searchDatabase: "ค้นหาฐานข้อมูล...",
selectSchema: "เลือก Schema",
diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts
index e6ac8f337c..be1459d168 100644
--- a/apps/desktop/src/i18n/locales/tr.ts
+++ b/apps/desktop/src/i18n/locales/tr.ts
@@ -1460,6 +1460,7 @@ export default withEnglishFallback({
selectCatalog: "Katalog seç",
searchCatalog: "Kataloglarda ara...",
selectDatabase: "Veritabanı seç",
+ selectConnectionRequired: "Önce bir bağlantı seçin",
selectDatabaseRequired: "Önce bir veritabanı seçin",
searchDatabase: "Veritabanlarında ara...",
selectSchema: "Şema seç",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 9243dedaeb..f102d92de9 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -2059,6 +2059,7 @@ export default withEnglishFallback({
discardAllChanges: "全部不保存",
saveAllChanges: "全部保存",
selectConnection: "选择连接",
+ selectConnectionRequired: "请先选择连接",
searchConnection: "搜索连接...",
selectCatalog: "选择 Catalog",
searchCatalog: "搜索 Catalog...",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index c215fe451f..a87e81e9a3 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -1885,6 +1885,7 @@ export default withEnglishFallback({
discardAllChanges: "全部捨棄",
saveAllChanges: "全部儲存",
selectConnection: "選擇連線",
+ selectConnectionRequired: "請先選擇連線",
searchConnection: "搜尋連線……",
selectCatalog: "選擇 Catalog",
searchCatalog: "搜尋 Catalog……",
diff --git a/packages/app-tests/savedSqlConnectionSwitch.test.ts b/packages/app-tests/savedSqlConnectionSwitch.test.ts
index 2afe12f2cc..d4ce35aea2 100644
--- a/packages/app-tests/savedSqlConnectionSwitch.test.ts
+++ b/packages/app-tests/savedSqlConnectionSwitch.test.ts
@@ -59,9 +59,11 @@ async function setupSwitch(databaseType = "mysql") {
ensureConnected,
activeConnectionId: "conn-1",
};
+ const connectionRequiredTabId = { value: null as string | null };
const changeActiveConnection = new Function(
"resolveToolbarTab",
"connectionStore",
+ "connectionRequiredTabId",
"resolveDefaultDatabase",
"queryStore",
"getDatabaseOptions",
@@ -75,6 +77,7 @@ async function setupSwitch(databaseType = "mysql") {
)(
(id: string) => queryStore.tabs.find((candidate) => candidate.id === id),
connectionStore,
+ connectionRequiredTabId,
(_connection: unknown, options: string[]) => options[0] ?? "",
queryStore,
getDatabaseOptions,
@@ -85,7 +88,7 @@ async function setupSwitch(databaseType = "mysql") {
(key: string) => key,
(_translate: unknown, error: Error) => error.message,
) as (id: string, connectionId: string) => Promise<void>;
- return { savedSqlStore, original, queryStore, tab, tabId, ensureConnected, getDatabaseOptions, changeActiveConnection, rememberExternalSqlFileTarget };
+ return { savedSqlStore, original, queryStore, tab, tabId, ensureConnected, getDatabaseOptions, changeActiveConnection, rememberExternalSqlFileTarget, connectionRequiredTabId };
}
test.each(["connect", "databases"])("a target-save rollback invalidates the pending %s continuation", async (stage) => {
@@ -207,3 +210,17 @@ test("an external SQL switch still remembers the initialized database and schema
assert.deepEqual(context.rememberExternalSqlFileTarget.mock.calls.at(-1), ["/tmp/report.sql", { connectionId: "conn-2", database: "db-2", catalog: undefined, schema: "new_schema" }]);
assert.equal(apiMock.saveSavedSqlFile.mock.calls.length, 1);
});
+
+test("clears the connection-required prompt marker for the switching tab", async () => {
+ const context = await setupSwitch();
+ context.connectionRequiredTabId.value = context.tabId;
+ await context.changeActiveConnection(context.tabId, "conn-2");
+ assert.equal(context.connectionRequiredTabId.value, null);
+});
+
+test("leaves connection-required prompt marker untouched when switching a different tab", async () => {
+ const context = await setupSwitch();
+ context.connectionRequiredTabId.value = "different-tab-id";
+ await context.changeActiveConnection(context.tabId, "conn-2");
+ assert.equal(context.connectionRequiredTabId.value, "different-tab-id");
+});