fix(db2): resolve the login schema for unqualified completion columns

This commit is contained in:
ordinary being authored and GitHub committed 2026-10-04 22:17:40 +08:00
1 parent 87e3c0634a
commit 99d603fe15
2 files changed
+51 -1

No files matched your search

+12 -1
View File
@@ -9223,6 +9223,16 @@ export const useConnectionStore = defineStore("connection", () => {
return deduped;
}
/// Engines whose CURRENT SCHEMA defaults to the login identity. An unqualified
/// reference resolves against the login schema there, so `listCompletionColumns`
/// falls back to the username instead of letting its schema-required early return
/// discard the lookup. A query tab hits that state when it never picked a schema
/// (`jdbcDialect.ts` records a new query tab or a reopened `.sql` file as the
/// cases). Dameng was the first engine fixed for this (#8301); DB2's CURRENT
/// SCHEMA is documented as the authorization ID of the session user, so it needs
/// the same fallback.
const LOGIN_SCHEMA_COMPLETION_TYPES = new Set(["dameng", "db2"]);
async function listCompletionColumns(connectionId: string, database: string, table: string, schema?: string, context?: { clientSessionId?: string; version?: number; tableQuoted?: boolean; schemaQuoted?: boolean }, catalog?: string): Promise<SqlCompletionColumn[]> {
const config = getConfig(connectionId);
// Use the effective database type (e.g. a JDBC connection whose URL is
@@ -9236,7 +9246,8 @@ export const useConnectionStore = defineStore("connection", () => {
const uppercaseUnquotedIdentifier = oracleIdentifier || effectiveDbType === "saphana";
const completionTable = uppercaseUnquotedIdentifier && context?.tableQuoted === false ? table.toUpperCase() : table;
const normalizedSchema = schema?.trim();
const rawCompletionSchema = effectiveDbType === "spanner" ? normalizedSchema : normalizedSchema || (effectiveDbType === "dameng" ? config?.username?.trim() || undefined : undefined);
const loginSchema = effectiveDbType && LOGIN_SCHEMA_COMPLETION_TYPES.has(effectiveDbType) ? config?.username?.trim() || undefined : undefined;
const rawCompletionSchema = effectiveDbType === "spanner" ? normalizedSchema : normalizedSchema || loginSchema;
const completionSchema = uppercaseUnquotedIdentifier && rawCompletionSchema && context?.schemaQuoted === false ? rawCompletionSchema.toUpperCase() : rawCompletionSchema;
const usesCurrentSchema = usesOracleCurrentSchemaCompletion(effectiveDbType, completionSchema);
const hasCompletionSchema = completionSchema != null && (completionSchema !== "" || effectiveDbType === "spanner");