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
use odbc_sys::{SmallInt, SqlDataType, ULen, WChar};
use std::char::{decode_utf16, DecodeUtf16Error};
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Nullable {
Unknown,
Nullable,
NoNulls,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ColumnDescription {
pub name: Vec<WChar>,
pub data_type: SqlDataType,
pub column_size: ULen,
pub decimal_digits: SmallInt,
pub nullable: Nullable,
}
impl Default for ColumnDescription {
fn default() -> Self {
Self {
name: Vec::new(),
data_type: SqlDataType::UNKNOWN_TYPE,
column_size: 0,
decimal_digits: 0,
nullable: Nullable::Unknown,
}
}
}
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,
}
}
}