Skip to main content

uqa_sql/params/
packed.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Host binary input retains SQL identity and uses the native representation owners.
8
9use super::{ColumnType, Produced, ProductionControl, SQLError, SQLParam, Value};
10use crate::expr::bit_string::{self, BitStringKind};
11
12impl SQLParam {
13    /// Construct a UUID from canonical network-order octets without applying version or variant restrictions.
14    pub fn uuid_with_control(
15        bytes: [u8; 16],
16        control: &ProductionControl<'_>,
17    ) -> Result<Produced<Self>, SQLError> {
18        let (text, memory) = crate::expr::format_uuid_with_control(bytes, control)?.into_parts();
19        Ok(control.finish(
20            Self::typed_scalar(Value::Str(text), ColumnType::Uuid),
21            memory,
22        )?)
23    }
24
25    /// Copy a packed fixed or varying bit value with no declared length modifier. Logical length and SQL kind remain independent.
26    pub fn packed_bits_with_control(
27        bytes: &[u8],
28        bit_length: u32,
29        kind: BitStringKind,
30        control: &ProductionControl<'_>,
31    ) -> Result<Produced<Self>, SQLError> {
32        let (bits, memory) =
33            bit_string::from_packed_with_control(bytes, bit_length, control)?.into_parts();
34        let ty = match kind {
35            BitStringKind::Fixed => ColumnType::Bit(None),
36            BitStringKind::Varying => ColumnType::VarBit(None),
37        };
38        Ok(control.finish(Self::typed_scalar(Value::BitString(bits), ty), memory)?)
39    }
40}
41
42#[cfg(test)]
43mod tests;