From 9c22856285e80c0c178114d70a99b8e7a69053e4 Mon Sep 17 00:00:00 2001 From: U1 <56990620+CHNHJF@users.noreply.github.com> Date: Tue, 15 Sep 2026 14:30:39 +0800 Subject: [PATCH] fix(sidebar): respect identifier quote setting when creating views --- .../sidebar/SidebarTreeRuntimeHost.vue | 2 ++ ...RuntimeHost.createViewQuoteSetting.spec.ts | 27 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.createViewQuoteSetting.spec.ts diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue index 036ab72e5a..f0c188b924 100644 --- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue +++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue @@ -4493,6 +4493,8 @@ function createView() { identifierQuote: connectionStore.connectionIdentifierQuote?.(node.connectionId), schema: node.schema, tableName: viewName, + includeDatabaseName: settingsStore.editorSettings.generateSqlIncludeDatabaseName, + quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers, }); const tabId = queryStore.createTab(node.connectionId, node.database, t("contextMenu.createView"), "query", node.schema, undefined, node.catalog); queryStore.updateSql(tabId, `CREATE VIEW ${viewSqlName} AS\nSELECT\n *\nFROM table_name;\n`); diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.createViewQuoteSetting.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.createViewQuoteSetting.spec.ts new file mode 100644 index 0000000000..e8c0286af7 --- /dev/null +++ b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.createViewQuoteSetting.spec.ts @@ -0,0 +1,27 @@ +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { describe, expect, it } from "vitest"; + +const runtimeSource = readFileSync(fileURLToPath(new URL("../SidebarTreeRuntimeHost.vue", import.meta.url)), "utf8"); + +function functionSource(name: string): string { + const start = runtimeSource.indexOf(`function ${name}(`); + expect(start, `${name} not found`).toBeGreaterThan(-1); + const next = runtimeSource.indexOf("\nfunction ", start + 1); + return runtimeSource.slice(start, next === -1 ? undefined : next); +} + +describe("SidebarTreeRuntimeHost createView identifier quoting (#9099)", () => { + it("forwards the generate-SQL settings to qualifiedTableName", () => { + const createView = functionSource("createView"); + const callStart = createView.indexOf("qualifiedTableName({"); + expect(callStart).toBeGreaterThan(-1); + const callEnd = createView.indexOf("});", callStart); + const call = createView.slice(callStart, callEnd); + + // Turning off the quote toggle must reach qualifiedTableName; otherwise it + // unconditionally quotes the schema/view name regardless of the setting. + expect(call).toContain("quoteIdentifiers: settingsStore.editorSettings.generateSqlQuoteIdentifiers"); + expect(call).toContain("includeDatabaseName: settingsStore.editorSettings.generateSqlIncludeDatabaseName"); + }); +});