Skip to main content

uqa_sql/routines/
diagnostics.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Routine diagnostic frames use declaration identities, independently of SQLERRM.
8
9use crate::ast::CreateFunction;
10
11pub enum SQLRoutineStage {
12    Inlining,
13    Startup,
14    Statement(usize),
15}
16
17pub fn sql_context(definition: &CreateFunction, stage: SQLRoutineStage) -> String {
18    let name = crate::compiler::parse_regobject_name(&definition.name)
19        .and_then(|mut names| names.pop())
20        .unwrap_or_else(|| definition.name.clone());
21    let stage = match stage {
22        SQLRoutineStage::Inlining => "during inlining".to_string(),
23        SQLRoutineStage::Startup => "during startup".to_string(),
24        SQLRoutineStage::Statement(position) => format!("statement {position}"),
25    };
26    format!("SQL function \"{name}\" {stage}")
27}