Skip to main content

uqa_engine/
parameters.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Statement and retained-resource adapters for catalog-aware host value input.
8
9use crate::Engine;
10use uqa_core::memory::{Produced, ProductionControl};
11use uqa_sql::{SQLError, SQLParam};
12
13impl Engine {
14    /// Construct typed range bounds with the native statement scope; SQL owns endpoint conversion and Execution invokes selected catalog support.
15    pub fn create_range_parameter_with_control(
16        &self,
17        type_name: &str,
18        bounds: uqa_sql::params::RangeParameterBounds<'_>,
19        control: &ProductionControl<'_>,
20    ) -> Result<Produced<SQLParam>, SQLError> {
21        self.with_direct_query_snapshot(
22            false,
23            |engine| {
24                uqa_sql::params::create_range_parameter_with_control(
25                    type_name, bounds, engine, engine, control,
26                )
27            },
28            std::convert::identity,
29        )
30    }
31
32    /// Normalize typed range members and validate an enclosing domain in the native statement scope.
33    pub fn create_multirange_parameter_with_control(
34        &self,
35        type_name: &str,
36        members: &[SQLParam],
37        control: &ProductionControl<'_>,
38    ) -> Result<Produced<SQLParam>, SQLError> {
39        self.with_direct_query_snapshot(
40            false,
41            |engine| {
42                uqa_sql::params::create_multirange_parameter_with_control(
43                    type_name, members, engine, engine, control,
44                )
45            },
46            std::convert::identity,
47        )
48    }
49
50    /// Construct a typed host record in the native statement scope. SQL owns attribute selection, source binding, scalar casts and domain checks.
51    pub fn create_record_parameter_with_control(
52        &self,
53        type_name: &str,
54        fields: &[SQLParam],
55        control: &ProductionControl<'_>,
56    ) -> Result<Produced<SQLParam>, SQLError> {
57        self.with_direct_query_snapshot(
58            false,
59            |engine| {
60                uqa_sql::params::create_record_parameter_with_control(
61                    type_name, fields, engine, engine, control,
62                )
63            },
64            std::convert::identity,
65        )
66    }
67
68    /// Construct a typed host array in the session's native statement/catalog scope. SQL owns parameter identities, scalar conversion, dimensions and domain constraints.
69    pub fn create_array_parameter_with_control(
70        &self,
71        type_name: &str,
72        dimensions: &[usize],
73        lower_bounds: &[i32],
74        elements: &[SQLParam],
75        control: &ProductionControl<'_>,
76    ) -> Result<Produced<SQLParam>, SQLError> {
77        self.with_direct_query_snapshot(
78            false,
79            |engine| {
80                uqa_sql::params::create_array_parameter_with_control(
81                    type_name,
82                    dimensions,
83                    lower_bounds,
84                    elements,
85                    engine,
86                    engine,
87                    control,
88                )
89            },
90            std::convert::identity,
91        )
92    }
93
94    /// Create a typed parameter from external text, or a typed SQL NULL from `None`. Type input runs with the session's current catalog, privileges and presentation settings. Domain checks and input callbacks share native transaction admission, commit and failure recovery; the returned parameter retains the supplied production allowance.
95    pub fn create_typed_parameter_with_control(
96        &self,
97        type_name: &str,
98        text: Option<&str>,
99        control: &ProductionControl<'_>,
100    ) -> Result<Produced<SQLParam>, SQLError> {
101        self.with_direct_query_snapshot(
102            false,
103            |engine| {
104                uqa_sql::params::create_typed_parameter_with_control(
105                    type_name, text, engine, engine, control,
106                )
107            },
108            std::convert::identity,
109        )
110    }
111}