fix(sql): respect PostgreSQL ARRAY brackets

This commit is contained in:
jearhe authored and GitHub committed 2026-08-22 14:01:46 +08:00
1 parent 11179676ed
commit f274a599ed
6 files changed
+282 -57

No files matched your search

@@ -628,6 +628,66 @@ SELECT @value AS Message;`;
expect(executeCurrentSql).toHaveBeenCalledWith(resolvedSql, { openInNewResultTab: true });
});
it("executes the PostgreSQL ARRAY date-format query without opening the parameter dialog", async () => {
const sql = `
WITH rec_flow AS (
SELECT
order_no,
ARRAY[
concat(
operator_name, '(', COALESCE(remark, ''), ')[',
CASE operate_action
WHEN 'CREATE' THEN '创建工单'
WHEN 'SUBMIT' THEN '提交至下一处理人'
WHEN 'BACK' THEN '退回上一环节'
WHEN 'FINISH' THEN '已完成'
WHEN 'SUBMIT-CONFIRM' THEN '提交给创建人确认'
WHEN 'COMPLETE' THEN '确认工单'
ELSE operate_action
END, ']'
)
]::varchar[]
|| CASE
WHEN operate_action NOT IN ('FINISH','COMPLETE')
THEN ARRAY[target_handler_name]::varchar[]
ELSE ARRAY[]::varchar[]
END AS name_arr,
rn
FROM (
SELECT
'ORD20260821001' AS order_no,
'张三' AS operator_name,
'发起流程' AS remark,
'SUBMIT' AS operate_action,
'李四' AS target_handler_name,
1 AS rn
) AS mock_t3_flow
)
SELECT to_char(current_timestamp, 'yyyy-MM-dd HH24:mi:ss');
`;
const activeTab = ref<QueryTab | undefined>(queryTab("app"));
const activeConnection = ref<ConnectionConfig | undefined>(connection("postgres"));
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
const queryStore = useQueryStore();
const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {
if (activeTab.value) activeTab.value.result = { columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };
});
vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
const execution = useSqlExecution({
activeTab: computed(() => activeTab.value),
activeConnection: computed(() => activeConnection.value),
executableSql: computed(() => sql),
activeOutputView,
});
await execution.tryExecute();
expect(execution.showSqlParameterDialog.value).toBe(false);
expect(execution.sqlParameterNames.value).toEqual([]);
expect(executeCurrentSql).toHaveBeenCalledWith(sql, {});
});
it("executes Oracle database-link queries without opening the parameter dialog", async () => {
const sql = "SELECT 1 FROM DUAL@WDHIS160;";
const activeTab = ref<QueryTab | undefined>(queryTab("ORCL"));
@@ -144,7 +144,8 @@ export function useSqlExecution(deps: {
async function resolvedExecutableSql(source?: SqlExecutionOverride): Promise<{ sql: string; sourceOffset?: number; editorViewportRequestId?: number }> {
const atSetEnabled = resolveSqlVariableSyntaxToggles(settingsStore.editorSettings.sqlVariableSyntaxOverrides, deps.activeConnection.value?.db_type, settingsStore.editorSettings.sqlVariableSubstitutionEnabled).atSet;
const expand = (sql: string, declarationSql?: string) => (atSetEnabled ? expandSqlVariables(sql, { declarationSql }).sql : sql);
const databaseType = effectiveDatabaseTypeForConnection(deps.activeConnection.value) ?? deps.activeConnection.value?.db_type;
const expand = (sql: string, declarationSql?: string) => (atSetEnabled ? expandSqlVariables(sql, { declarationSql, databaseType }).sql : sql);
if (typeof source === "string") return { sql: expand(source) };
const resolved = deps.resolveExecutableSql ? await deps.resolveExecutableSql(source) : isSqlExecutionSnapshot(source) ? resolveExecutableSql(source.fullSql, source.selectedSql, { cursorPos: source.cursorPos }) : deps.executableSql.value;