fix(navigator): preserve table identity when opening objects

This commit is contained in:
vrustx authored and GitHub committed 2026-07-16 15:20:03 +08:00
1 parent 552e1741db
commit e226a5670e
3 files changed
+55 -1

No files matched your search

@@ -50,6 +50,18 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
})();
const targetTab = queryStore.tabs.find((tab) => tab.id === tabId);
if (targetTab) targetTab.tableInfoTab = options.tableInfoTab;
// Stamp the new table identity synchronously so SQL rebuilds (refresh,
// filters, row count) never read a stale tableMeta from a reused tab or
// fall back to parsing the schema-qualified tab title (issue #3613).
queryStore.setTableMeta(tabId, {
schema: target.schema,
catalog: target.catalog,
database: target.database,
tableName: target.tableName,
tableType: target.tableType ?? "TABLE",
columns: [],
primaryKeys: [],
});
queryStore.setExecuting(tabId, true);
try {
+14 -1
View File
@@ -2,6 +2,19 @@ import type { QueryTab, ColumnInfo } from "@/types/database";
export type DataTabTableMeta = NonNullable<QueryTab["tableMeta"]>;
// Data tabs opened from the object browser are titled "<schema>.<table>".
// When the tab has no usable tableMeta yet, strip the schema prefix so SQL
// rebuilt from this fallback does not qualify the table twice
// (e.g. [dbo].[dbo.users] on SQL Server — see issue #3613).
function titleTableName(tab: QueryTab): string {
const title = tab.title.trim();
const schema = tab.schema?.trim();
if (schema && title.length > schema.length + 1 && title.startsWith(`${schema}.`)) {
return title.slice(schema.length + 1);
}
return title;
}
function fallbackColumnInfo(name: string): ColumnInfo {
return {
name,
@@ -16,7 +29,7 @@ function fallbackColumnInfo(name: string): ColumnInfo {
export function tableMetaForDataTab(tab: QueryTab | undefined): DataTabTableMeta | undefined {
if (!tab || tab.mode !== "data") return undefined;
if (tab.tableMeta?.columns.length) return tab.tableMeta;
const tableName = tab.title.trim();
const tableName = tab.tableMeta?.tableName.trim() || titleTableName(tab);
if (!tableName) return undefined;
// Keep filters usable when the table identity loaded but its column metadata did not.