use crate::{
CursorImpl, Error, TruncationInfo,
buffers::{FetchRow, FetchRowMember as _},
handles::{SqlText, Statement, StatementRef},
parameter::VarCharArray,
};
#[derive(Clone, Copy, Default)]
pub struct TablesRow {
pub catalog: VarCharArray<128>,
pub schema: VarCharArray<128>,
pub table: VarCharArray<255>,
pub table_type: VarCharArray<255>,
pub remarks: VarCharArray<1024>,
}
unsafe impl FetchRow for TablesRow {
unsafe fn bind_columns_to_cursor(&mut self, mut cursor: StatementRef<'_>) -> Result<(), Error> {
unsafe {
self.catalog.bind_to_col(1, &mut cursor)?;
self.schema.bind_to_col(2, &mut cursor)?;
self.table.bind_to_col(3, &mut cursor)?;
self.table_type.bind_to_col(4, &mut cursor)?;
self.remarks.bind_to_col(5, &mut cursor)?;
Ok(())
}
}
fn find_truncation(&self) -> Option<TruncationInfo> {
if let Some(t) = self.catalog.find_truncation(0) {
return Some(t);
}
if let Some(t) = self.schema.find_truncation(1) {
return Some(t);
}
if let Some(t) = self.table.find_truncation(2) {
return Some(t);
}
if let Some(t) = self.table_type.find_truncation(3) {
return Some(t);
}
if let Some(t) = self.remarks.find_truncation(4) {
return Some(t);
}
None
}
}
pub fn execute_tables<S>(
mut statement: S,
catalog_name: &str,
schema_name: &str,
table_name: &str,
table_type: &str,
) -> Result<CursorImpl<S>, Error>
where
S: Statement,
{
statement
.tables(
&SqlText::new(catalog_name),
&SqlText::new(schema_name),
&SqlText::new(table_name),
&SqlText::new(table_type),
)
.into_result(&statement)?;
debug_assert_ne!(statement.num_result_cols().unwrap(), 0);
let cursor = unsafe { CursorImpl::new(statement) };
Ok(cursor)
}