uqa_sql/binding/routine_parameters/
production.rs1use super::{
10 ColumnType, RoutineParameterData, RoutineParameterScope, RowSchema, SQLError,
11 ROUTINE_PARAMETERS,
12};
13use uqa_core::memory::{ProductionControl, ProductionVec};
14
15#[cfg(test)]
16mod tests;
17
18impl RoutineParameterScope {
19 pub fn new_with_control<'a>(
20 function: &str,
21 columns: impl Iterator<Item = (&'a str, Option<&'a ColumnType>)> + Clone,
22 control: &ProductionControl<'_>,
23 ) -> Result<Self, SQLError> {
24 control.check()?;
25 let schema = RowSchema::with_parameter_metadata_with_control(
26 function,
27 *ROUTINE_PARAMETERS,
28 columns.clone(),
29 control,
30 )?;
31 let function = control.copy_text(function)?;
32 let mut names = ProductionVec::new(*control);
33 names.reserve(columns.clone().count())?;
34 for (name, _) in columns {
35 names.push_produced(control.copy_text(name)?)?;
36 }
37 let (function, function_memory) = function.into_parts();
38 let (names, names_memory) = names.finish()?.into_parts();
39 let data = control
40 .finish(
41 RoutineParameterData {
42 function,
43 names,
44 schema,
45 },
46 control.combine(function_memory, names_memory),
47 )?
48 .into_shared(control)?;
49 Ok(Self { data })
50 }
51}