uqa_engine/user_functions.rs
1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! User-defined routine API, session controls, and canonical SQL type exports.
8
9pub(crate) use uqa_sql::routines::SQLUserFunction;
10
11use crate::Engine;
12impl Engine {
13 /// Current nesting cap for user-defined routine calls.
14 pub fn sql_function_depth_limit(&self) -> usize {
15 self.runtime
16 .function_depth_limit
17 .load(std::sync::atomic::Ordering::Relaxed)
18 }
19
20 /// Adjust the nesting cap for user-defined routine calls
21 /// (minimum 1). Mirrors `PostgreSQL`'s `max_stack_depth` role for
22 /// recursive functions.
23 pub fn set_sql_function_depth_limit(&self, limit: usize) {
24 self.runtime
25 .function_depth_limit
26 .store(limit.max(1), std::sync::atomic::Ordering::Relaxed);
27 }
28
29 /// Queue a notice (`RAISE NOTICE` / `WARNING` / ...).
30 pub(crate) fn push_sql_notice(&self, notice: uqa_sql::SQLNotice) {
31 self.query_runtime_view().push_notice(notice);
32 }
33
34 /// Drain the queued notices in emission order, each with its level, SQLSTATE, message, and the detail and hint `PostgreSQL` reports as fields of their own.
35 pub fn take_sql_notices(&self) -> Vec<uqa_sql::SQLNotice> {
36 self.runtime.notices.take()
37 }
38
39 /// Prepare a destination for the oldest notice before removing it. The callback runs only
40 /// when a notice exists; rejection or unwinding preserves the queue. It must not reenter
41 /// this Engine or its notice queue. Success moves the original notice and prepared owner.
42 pub fn try_take_sql_notice_with<T, E>(
43 &self,
44 prepare: impl FnOnce(&uqa_sql::SQLNotice) -> Result<T, E>,
45 ) -> Result<Option<(uqa_sql::SQLNotice, T)>, E> {
46 self.runtime.notices.try_take_with(prepare)
47 }
48}