use super::data_type::DataType;
use std::char::{decode_utf16, DecodeUtf16Error};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Nullable {
Unknown,
Nullable,
NoNulls,
}
impl Default for Nullable {
fn default() -> Self {
Nullable::Unknown
}
}
impl Nullable {
pub fn new(nullable: odbc_sys::Nullable) -> Self {
match nullable {
odbc_sys::Nullable::UNKNOWN => Nullable::Unknown,
odbc_sys::Nullable::NO_NULLS => Nullable::NoNulls,
odbc_sys::Nullable::NULLABLE => Nullable::Nullable,
other => panic!("ODBC returned invalid value for Nullable: {:?}", other),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Default)]
pub struct ColumnDescription {
pub name: Vec<u16>,
pub data_type: DataType,
pub nullable: Nullable,
}
impl ColumnDescription {
pub fn name_to_string(&self) -> Result<String, DecodeUtf16Error> {
decode_utf16(self.name.iter().copied()).collect()
}
pub fn could_be_nullable(&self) -> bool {
match self.nullable {
Nullable::Nullable | Nullable::Unknown => true,
Nullable::NoNulls => false,
}
}
}