fix(editor): complete Dameng columns without selected schema
This commit is contained in:
2 files changed
+39
-1
No files matched your search
@@ -72,6 +72,18 @@ function sqlServerConnection(): ConnectionConfig {
|
|||||||
} as ConnectionConfig;
|
} as ConnectionConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function damengConnection(): ConnectionConfig {
|
||||||
|
return {
|
||||||
|
...postgresConnection(),
|
||||||
|
id: "dameng-1",
|
||||||
|
name: "Dameng",
|
||||||
|
db_type: "dameng",
|
||||||
|
port: 5236,
|
||||||
|
username: "dbx_test",
|
||||||
|
database: "",
|
||||||
|
} as ConnectionConfig;
|
||||||
|
}
|
||||||
|
|
||||||
function dorisConnection(): ConnectionConfig {
|
function dorisConnection(): ConnectionConfig {
|
||||||
return {
|
return {
|
||||||
...postgresConnection(),
|
...postgresConnection(),
|
||||||
@@ -295,6 +307,32 @@ describe("connectionStore completion assistant", () => {
|
|||||||
expect(store.lookupLocalCompletionColumns("oracle-1", "ORCL", "ORDERS")).toEqual([]);
|
expect(store.lookupLocalCompletionColumns("oracle-1", "ORCL", "ORDERS")).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("uses the Dameng login schema for unqualified column completion", async () => {
|
||||||
|
const completionAssistantSearch = vi.fn().mockRejectedValue(new Error("assistant unavailable"));
|
||||||
|
const getColumns = vi.fn().mockResolvedValue([{ name: "ID", data_type: "BIGINT", is_nullable: false, column_default: null, is_primary_key: true, extra: null, comment: null }]);
|
||||||
|
|
||||||
|
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||||
|
vi.doMock("@/lib/backend/api", () => ({
|
||||||
|
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||||
|
completionAssistantSearch,
|
||||||
|
getColumns,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||||
|
const store = useConnectionStore();
|
||||||
|
store.connections = [damengConnection()];
|
||||||
|
store.connectedIds.add("dameng-1");
|
||||||
|
|
||||||
|
const first = await store.listCompletionColumns("dameng-1", "", "tb_user");
|
||||||
|
const cached = await store.listCompletionColumns("dameng-1", "", "tb_user");
|
||||||
|
|
||||||
|
expect(completionAssistantSearch).toHaveBeenCalledTimes(1);
|
||||||
|
expect(getColumns).toHaveBeenCalledTimes(1);
|
||||||
|
expect(getColumns).toHaveBeenCalledWith("dameng-1", "", "dbx_test", "tb_user", undefined, undefined);
|
||||||
|
expect(first).toEqual([expect.objectContaining({ name: "ID", table: "tb_user", schema: "dbx_test" })]);
|
||||||
|
expect(cached).toEqual(first);
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects assistant columns returned for a different MySQL parent table", async () => {
|
it("rejects assistant columns returned for a different MySQL parent table", async () => {
|
||||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||||
candidates: [
|
candidates: [
|
||||||
|
|||||||
@@ -6077,7 +6077,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
const oracleIdentifier = config?.db_type === "oracle";
|
const oracleIdentifier = config?.db_type === "oracle";
|
||||||
const uppercaseUnquotedIdentifier = oracleIdentifier || config?.db_type === "saphana";
|
const uppercaseUnquotedIdentifier = oracleIdentifier || config?.db_type === "saphana";
|
||||||
const completionTable = uppercaseUnquotedIdentifier && context?.tableQuoted === false ? table.toUpperCase() : table;
|
const completionTable = uppercaseUnquotedIdentifier && context?.tableQuoted === false ? table.toUpperCase() : table;
|
||||||
const rawCompletionSchema = schema?.trim() || undefined;
|
const rawCompletionSchema = schema?.trim() || (config?.db_type === "dameng" ? config.username?.trim() || undefined : undefined);
|
||||||
const completionSchema = uppercaseUnquotedIdentifier && rawCompletionSchema && context?.schemaQuoted === false ? rawCompletionSchema.toUpperCase() : rawCompletionSchema;
|
const completionSchema = uppercaseUnquotedIdentifier && rawCompletionSchema && context?.schemaQuoted === false ? rawCompletionSchema.toUpperCase() : rawCompletionSchema;
|
||||||
const usesOracleCurrentSchema = config?.db_type === "oracle" && !completionSchema;
|
const usesOracleCurrentSchema = config?.db_type === "oracle" && !completionSchema;
|
||||||
if (isSchemaAwareDatabase(connectionId) && !connectionUsesDatabaseObjectTreeMode(config) && !completionSchema && !usesOracleCurrentSchema) {
|
if (isSchemaAwareDatabase(connectionId) && !connectionUsesDatabaseObjectTreeMode(config) && !completionSchema && !usesOracleCurrentSchema) {
|
||||||
|
|||||||
Reference in new issue
Block a user