1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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,
}
}
}