uqa_sql/expr/composites/descriptor/
production.rs1use super::{CompositeAttribute, CompositeTypeDescriptor};
8use crate::{ast::ColumnType, expr::composites::DroppedCompositeAttribute, SQLError};
9use uqa_core::memory::{Produced, ProductionControl, ProductionVec};
10
11impl CompositeTypeDescriptor {
12 pub fn from_metadata_with_control<'a>(
14 type_oid: u32,
15 relation_oid: u32,
16 attributes: impl IntoIterator<
17 Item = Result<(&'a str, &'a ColumnType, i16, Option<u32>), SQLError>,
18 >,
19 dropped: impl IntoIterator<Item = Result<DroppedCompositeAttribute, SQLError>>,
20 control: &ProductionControl<'_>,
21 ) -> Result<Produced<Self>, SQLError> {
22 control.check()?;
23 let mut removed = ProductionVec::new(*control);
24 for attribute in dropped {
25 control.check()?;
26 removed.push_copy(attribute?)?;
27 }
28 let mut fields = ProductionVec::new(*control);
29 for attribute in attributes {
30 control.check()?;
31 let (name, ty, number, collation_oid) = attribute?;
32 let (name, name_memory) = control.copy_text(name)?.into_parts();
33 let (ty, type_memory) = ty.clone_with_control(control)?.into_parts();
34 fields.push_produced(control.finish(
35 CompositeAttribute {
36 name,
37 ty,
38 collation_oid,
39 number,
40 },
41 control.combine(name_memory, type_memory),
42 )?)?;
43 }
44 let (dropped, dropped_memory) = removed.finish()?.into_parts();
45 let (attributes, memory) = fields.finish()?.into_parts();
46 Ok(control.finish(
47 Self {
48 dropped,
49 type_oid,
50 relation_oid,
51 attributes,
52 },
53 control.combine(memory, dropped_memory),
54 )?)
55 }
56}