fix(kingbase): preserve query schema context
This commit is contained in:
6 files changed
+306
-49
No files matched your search
@@ -45,6 +45,7 @@ import { findTreeNodeById, resolveNewQueryTarget, resolveNewQueryInitialSql } fr
|
||||
import { sqlObjectNavigationSourceKind, sqlObjectNavigationTableType, type SqlObjectNavigationTarget } from "@/lib/sql/sqlNavigation";
|
||||
import { buildExecutableObjectSourceStatements, executeObjectSourceSave } from "@/lib/table/objectSourceEditor";
|
||||
import { schemaAfterConnectionSwitch } from "@/lib/schema/connectionSchemaInitialization";
|
||||
import { resolveHistorySqlRestoreTarget } from "@/lib/history/historyRestoreTarget";
|
||||
import { resolveExecutableSql, resolveExecutableSqlWithBackend, type SqlExecutionSnapshot } from "@/lib/sql/sqlExecutionTarget";
|
||||
import { uuid } from "@/lib/common/utils";
|
||||
import { isMacOS, isWindows } from "@/lib/backend/platform";
|
||||
@@ -254,11 +255,14 @@ function restoreHistorySql(sql: string, entry: HistoryEntry) {
|
||||
return;
|
||||
}
|
||||
|
||||
const connectionId = entry.connection_id || tab?.connectionId || connectionStore.connections[0]?.id;
|
||||
if (!connectionId) return;
|
||||
const config = connectionStore.getConfig(connectionId);
|
||||
const database = entry.database || tab?.database || (config ? resolveDefaultDatabase(config, []) : "");
|
||||
const tabId = queryStore.createTab(connectionId, database || "", t("tabs.sql"));
|
||||
const target = resolveHistorySqlRestoreTarget({
|
||||
entry,
|
||||
activeTab: tab,
|
||||
firstConnectionId: connectionStore.connections[0]?.id,
|
||||
getConfig: (connectionId) => connectionStore.getConfig(connectionId),
|
||||
});
|
||||
if (!target) return;
|
||||
const tabId = queryStore.createTab(target.connectionId, target.database, t("tabs.sql"), "query", target.schema);
|
||||
queryStore.updateSql(tabId, sql);
|
||||
}
|
||||
|
||||
@@ -1554,7 +1558,8 @@ function ensureQueryTab(): string {
|
||||
if (tab && tab.mode === "query") return tab.id;
|
||||
const connId = connectionStore.activeConnectionId || connectionStore.connections[0]?.id || "";
|
||||
const db = tab?.connectionId === connId ? tab.database : connectionStore.getConfig(connId)?.database || "";
|
||||
return queryStore.createTab(connId, db, undefined, "query");
|
||||
const schema = tab?.connectionId === connId ? tab.schema : undefined;
|
||||
return queryStore.createTab(connId, db, undefined, "query", schema);
|
||||
}
|
||||
|
||||
function routeAiRedisCommand(command: string, execute: boolean): boolean {
|
||||
|
||||
@@ -85,6 +85,10 @@ describe("query execution schema", () => {
|
||||
expect(connectionQueryExecutionSchema({ db_type: "postgres" }, "app", "reporting", false)).toBe("reporting");
|
||||
});
|
||||
|
||||
it("prefers an explicit schema for Kingbase query execution", () => {
|
||||
expect(connectionQueryExecutionSchema({ db_type: "kingbase" }, "qinzhou", "sdy_smartsite", false)).toBe("sdy_smartsite");
|
||||
});
|
||||
|
||||
it("does not send a schema for MySQL database context", () => {
|
||||
expect(connectionQueryExecutionSchema({ db_type: "mysql" }, "app", undefined, false)).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import type { HistoryEntry } from "@/lib/backend/api";
|
||||
import { resolveDefaultDatabase } from "@/lib/database/defaultDatabase";
|
||||
import type { ConnectionConfig, QueryTab } from "@/types/database";
|
||||
|
||||
export interface HistorySqlRestoreTarget {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema?: string;
|
||||
}
|
||||
|
||||
export function resolveHistorySqlRestoreTarget(options: { entry: HistoryEntry; activeTab?: QueryTab; firstConnectionId?: string; getConfig: (connectionId: string) => ConnectionConfig | undefined }): HistorySqlRestoreTarget | null {
|
||||
const { entry, activeTab, firstConnectionId, getConfig } = options;
|
||||
const connectionId = entry.connection_id || activeTab?.connectionId || firstConnectionId;
|
||||
if (!connectionId) return null;
|
||||
const config = getConfig(connectionId);
|
||||
const database = entry.database || activeTab?.database || (config ? resolveDefaultDatabase(config, []) : "");
|
||||
const schema = activeTab?.connectionId === connectionId && activeTab.database === database ? activeTab.schema : undefined;
|
||||
return { connectionId, database: database || "", schema };
|
||||
}
|
||||
Reference in new issue
Block a user