use crate::constants;
use crate::db_type::DbType;
use crate::error::Error;
use crate::metadata::Metadata;
#[derive(Clone)]
pub(crate) struct BindInfo {
pub(crate) name: String,
pub(crate) is_return_bind: bool,
pub(crate) metadata: Option<Metadata>,
pub(crate) bind_direction: u8,
}
impl BindInfo {
pub(crate) fn check_and_set_metadata(
&mut self,
replace: bool,
desired_type: &'static DbType,
desired_max_size: usize,
) -> Result<(), Error> {
let mut matches: bool = false;
if let Some(metadata) = self.metadata.as_ref() {
if metadata.db_type() == desired_type {
matches = metadata.max_size() as usize >= desired_max_size;
} else if !replace {
return Err(Error::different_types(
metadata.db_type(),
desired_type,
));
}
}
if !matches {
let mut metadata =
Metadata::new_scalar(desired_type, desired_max_size);
if self.is_return_bind {
metadata.set_is_array(true);
}
self.metadata = Some(metadata);
}
Ok(())
}
pub(crate) fn is_input_bind(&self) -> bool {
!self.is_return_bind
&& self.bind_direction & constants::TTC_BIND_DIR_INPUT != 0
}
pub(crate) fn is_output_bind(&self) -> bool {
self.is_return_bind
|| self.bind_direction & constants::TTC_BIND_DIR_OUTPUT != 0
}
}