Skip to main content

sqlx_mssql_odbc_core/
column.rs

1use crate::{Mssql, MssqlTypeInfo};
2
3/// Column metadata for an MSSQL result set via ODBC.
4#[derive(Debug, Clone, PartialEq, Eq)]
5#[cfg_attr(feature = "offline", derive(serde::Serialize, serde::Deserialize))]
6pub struct MssqlColumn {
7    ordinal: usize,
8    name: String,
9    type_info: MssqlTypeInfo,
10    /// Column nullability as reported by ODBC.
11    ///
12    /// - `Some(true)` — column is nullable
13    /// - `Some(false)` — column is NOT NULL
14    /// - `None` — nullability is unknown
15    nullable: Option<bool>,
16}
17
18impl MssqlColumn {
19    /// Creates column metadata.
20    pub fn new(
21        ordinal: usize,
22        name: impl Into<String>,
23        type_info: MssqlTypeInfo,
24        nullable: Option<bool>,
25    ) -> Self {
26        Self {
27            ordinal,
28            name: name.into(),
29            type_info,
30            nullable,
31        }
32    }
33
34    /// Returns the nullability of this column, as reported by ODBC.
35    ///
36    /// - `Some(true)` — column is nullable
37    /// - `Some(false)` — column is NOT NULL
38    /// - `None` — nullability is unknown
39    pub fn nullable(&self) -> Option<bool> {
40        self.nullable
41    }
42}
43
44impl sqlx_core::column::Column for MssqlColumn {
45    type Database = Mssql;
46
47    fn ordinal(&self) -> usize {
48        self.ordinal
49    }
50
51    fn name(&self) -> &str {
52        &self.name
53    }
54
55    fn type_info(&self) -> &MssqlTypeInfo {
56        &self.type_info
57    }
58}