Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(completion): respect identifier quoting for oracle completions

Melody Ruch2a8e329d0508
diff --git a/apps/desktop/src/components/editor/QueryEditor.vue b/apps/desktop/src/components/editor/QueryEditor.vue
index 9c667c827f..261f5c77d1 100644
--- a/apps/desktop/src/components/editor/QueryEditor.vue
+++ b/apps/desktop/src/components/editor/QueryEditor.vue
@@ -5292,6 +5292,7 @@ async function provideSqlCompletions(context: CompletionContext) {
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
+ quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
});
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
}
@@ -5353,6 +5354,7 @@ async function provideSqlCompletions(context: CompletionContext) {
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
+ quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
});
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
}
@@ -5693,6 +5695,7 @@ function buildLocalSqlCompletionResult(completionContext: ReturnType<typeof getS
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
+ quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
});
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
@@ -6196,6 +6199,7 @@ async function performAsyncCompletionWithResult(epoch: number, completionContext
keywordCase: settingsStore.editorSettings.sqlFormatter.keywordCase,
functionCase: settingsStore.editorSettings.sqlFormatter.functionCase,
autoAliasTables: settingsStore.editorSettings.autoAliasTables,
+ quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers,
});
return buildSqlCompletionResult(items, completionContext, fullDoc, position);
diff --git a/apps/desktop/src/lib/__tests__/sql/oracleIdentifierQuoting.spec.ts b/apps/desktop/src/lib/__tests__/sql/oracleIdentifierQuoting.spec.ts
index 210b564d18..8cc15b1203 100644
--- a/apps/desktop/src/lib/__tests__/sql/oracleIdentifierQuoting.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sql/oracleIdentifierQuoting.spec.ts
@@ -70,3 +70,23 @@ describe("oracle completion apply identifiers", () => {
expect(routine?.apply).toBe('"GetBom"()');
});
});
+
+describe("oracle completion with identifier quoting disabled (#9735)", () => {
+ const sql = "SELECT t.c FROM abc t";
+ const cursor = "SELECT t.c".length;
+ const input = {
+ databaseType: "oracle" as const,
+ tables: [{ name: "abc", type: "table" as const }],
+ columnsByTable: new Map([["abc", [{ name: "col1", table: "abc" }]]]),
+ };
+ const applyOf = (extra: { quoteIdentifiers?: boolean }) => buildSqlCompletionItems(sql, cursor, { ...input, ...extra }).find((item) => item.label === "col1")?.apply;
+
+ it("keeps lowercase columns bare when quoting is disabled", () => {
+ expect(applyOf({ quoteIdentifiers: false })).toBe("col1");
+ });
+
+ it("still quotes lowercase columns by default and when quoting is enabled", () => {
+ expect(applyOf({})).toBe('"col1"');
+ expect(applyOf({ quoteIdentifiers: true })).toBe('"col1"');
+ });
+});
diff --git a/apps/desktop/src/lib/sql/sqlCompletion.ts b/apps/desktop/src/lib/sql/sqlCompletion.ts
index 1d4d04f920..97fe30b44b 100644
--- a/apps/desktop/src/lib/sql/sqlCompletion.ts
+++ b/apps/desktop/src/lib/sql/sqlCompletion.ts
@@ -1548,6 +1548,7 @@ export interface SqlCompletionProviderInput {
keywordCase?: SqlKeywordCase;
functionCase?: SqlKeywordCase;
autoAliasTables?: boolean;
+ quoteIdentifiers?: boolean;
}
export function buildSqlCompletionItems(
@@ -1567,6 +1568,7 @@ export function buildSqlCompletionItems(
keywordCase?: SqlKeywordCase;
functionCase?: SqlKeywordCase;
autoAliasTables?: boolean;
+ quoteIdentifiers?: boolean;
},
): SqlCompletionItem[] {
if (isSqlCompletionSuppressedContext(sql, cursor, input)) return [];
@@ -1589,7 +1591,9 @@ class SqlCompletionProvider {
private readonly input: SqlCompletionProviderInput,
) {
this.t = input.translations;
- this.dialect = sqlCompletionApplyDialect(input.databaseType, input.dialect);
+ const dialect = sqlCompletionApplyDialect(input.databaseType, input.dialect);
+ // "Quote identifiers in generated SQL" off: Oracle completion inserts bare names instead of quoting lowercase ones.
+ this.dialect = dialect === "oracle" && input.quoteIdentifiers === false ? undefined : dialect;
this.databaseType = input.databaseType;
}