@@ -80,6 +80,13 @@ const activeConnection = computed(() => {
8080
8181const activeTab = computed (() => tabStore .activeTab )
8282
83+ // Single source of truth for the database shown next to a result: the tab's
84+ // execution database, falling back to the sidebar selection while the tab is
85+ // still being created/synced.
86+ const activeDatabase = computed <string | undefined >(() =>
87+ activeTab .value ?.database || selectedDatabase .value || undefined ,
88+ )
89+
8390const editorContent = computed ({
8491 get : () => activeTab .value ?.content || ' ' ,
8592 set : (value : string ) => {
@@ -581,20 +588,11 @@ function handleSelectTopN(table: TableInfo, database: string, schema?: string, n
581588}
582589
583590function handleViewStructure(table : TableInfo , database : string , schema ? : string ) {
584- const query = ` -- Table structure for ${table .name }
585- -- Database: ${database }${schema ? ` \n -- Schema: ${schema }` : ' ' }
586-
587- -- View columns
588- SELECT column_name, data_type, is_nullable, column_default
589- FROM information_schema.columns
590- WHERE table_name = '${table .name }'${schema ? ` AND table_schema = '${schema }' ` : ' ' }; `
591-
592591 const connId = getActiveConnectionId ()
593- if (connId ) {
594- const tab = tabStore .createTab (connId , database , schema )
595- tabStore .updateTabContent (tab .id , query )
596- tabStore .updateTabName (tab .id , ` STRUCTURE_${table .name } ` )
597- }
592+ if (! connId )
593+ return
594+ ensureDatabaseContext (connId , database )
595+ tabStore .openTableViewTab (connId , database , table .name , schema , ' schema' )
598596}
599597
600598function handleExportData(_table : TableInfo , _database : string , _schema ? : string ) {
@@ -667,17 +665,21 @@ async function handleDestructiveConfirm() {
667665 }
668666}
669667
670- function handleSelectTable(table : TableInfo , database : string , schema ? : string ) {
671- const connId = getActiveConnectionId ()
672- if (! connId )
673- return
674- // Execute USE database to set the backend connection's database context.
675- // The Rust get_table_data MySQL branch ignores query.database, requiring
676- // the connection to already have a database selected.
668+ // Execute USE database to set the backend connection's database context.
669+ // The Rust get_table_data MySQL branch ignores query.database, requiring
670+ // the connection to already have a database selected.
671+ function ensureDatabaseContext(connId : string , database : string ) {
677672 const escapedDb = database .replace (/ `/ g , ' ``' )
678673 invoke (' execute_query' , { connectionId: connId , sql: ` USE \` ${escapedDb }\` ` }).catch (() => {
679674 // Best-effort: some databases don't support USE (e.g. SQLite)
680675 })
676+ }
677+
678+ function handleSelectTable(table : TableInfo , database : string , schema ? : string ) {
679+ const connId = getActiveConnectionId ()
680+ if (! connId )
681+ return
682+ ensureDatabaseContext (connId , database )
681683 tabStore .openTableViewTab (connId , database , table .name , schema )
682684}
683685
@@ -1202,6 +1204,7 @@ function closeResultPanel() {
12021204 :database =" activeTab .tableView .database "
12031205 :schema =" activeTab .tableView .schema "
12041206 :table-name =" activeTab .tableView .tableName "
1207+ :initial-sub-page =" activeTab .tableView .subPage ?? ' data' "
12051208 class="flex-1"
12061209 />
12071210
@@ -1355,7 +1358,7 @@ function closeResultPanel() {
13551358 <!-- Status info -->
13561359 <div v-if =" activeTab" class =" text-xs text-muted-foreground flex gap-2 items-center" >
13571360 <span v-if =" activeConnection" class =" font-medium" >{{ activeConnection.name }}</span >
1358- <span v-if =" activeConnection?.database " >/ {{ activeConnection.database }}</span >
1361+ <span v-if =" activeDatabase " >/ {{ activeDatabase }}</span >
13591362 </div >
13601363 </div >
13611364
@@ -1434,7 +1437,7 @@ function closeResultPanel() {
14341437 :execution-time =" activeTab ?.executionTime "
14351438 :sql =" activeTab ?.lastExecutedSql ?? activeTab ?.content "
14361439 :connection-id =" getConnectionId () ?? undefined "
1437- :database =" activeTab ?. database "
1440+ :database =" activeDatabase "
14381441 :explain-plan =" activeTab ?.explainPlan ?? null "
14391442 :is-explaining =" activeTab ?.isExplaining ?? false "
14401443 :explain-error =" activeTab ?.explainError ?? null "
@@ -1444,26 +1447,6 @@ function closeResultPanel() {
14441447 </template >
14451448 </div >
14461449 </div >
1447-
1448- <!-- Status bar -->
1449- <div class =" text-xs text-muted-foreground px-3 py-1 border-t bg-muted/30 flex items-center justify-between" >
1450- <div class =" flex gap-4 items-center" >
1451- <span v-if =" activeConnection?.database" >
1452- {{ t('pages.queries.status.database') }}: {{ activeConnection.database }}
1453- </span >
1454- </div >
1455- <div class =" flex gap-4 items-center" >
1456- <span v-if =" activeTab?.results" >
1457- {{ t('pages.queries.status.rows') }}: {{ activeTab.results.rows.length }}
1458- </span >
1459- <span v-if =" activeTab?.executionTime" >
1460- {{ t('pages.queries.status.time') }}: {{ activeTab.executionTime }}ms
1461- </span >
1462- <span v-if =" activeTab?.isExecuting" class =" text-primary" >
1463- {{ t('pages.queries.status.executing') }}
1464- </span >
1465- </div >
1466- </div >
14671450 </div >
14681451
14691452 <!-- Destructive Action Confirmation Dialog (Drop/Truncate Table) -->
0 commit comments