#[non_exhaustive]pub struct Column {
pub name: String,
pub index: usize,
pub type_name: String,
pub nullable: bool,
pub max_length: Option<u32>,
pub precision: Option<u8>,
pub scale: Option<u8>,
pub collation: Option<Collation>,
}Expand description
Column metadata describing a result set column.
This struct is marked #[non_exhaustive] to allow adding new fields
in future versions without breaking semver compatibility. Use
Column::new() or builder methods to construct instances.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringColumn name.
index: usizeColumn index (0-based).
type_name: StringSQL type name (e.g., “INT”, “NVARCHAR”).
nullable: boolWhether the column allows NULL values.
max_length: Option<u32>Maximum length for variable-length types.
precision: Option<u8>Precision for numeric types.
scale: Option<u8>Scale for numeric types.
collation: Option<Collation>Collation for string types (VARCHAR, CHAR, TEXT).
Used for proper encoding/decoding of non-Unicode string data. When present, enables collation-aware decoding that correctly handles locale-specific ANSI encodings (e.g., Shift_JIS, GB18030).
Implementations§
Source§impl Column
impl Column
Sourcepub fn new(
name: impl Into<String>,
index: usize,
type_name: impl Into<String>,
) -> Self
pub fn new( name: impl Into<String>, index: usize, type_name: impl Into<String>, ) -> Self
Create a new column with basic metadata.
Sourcepub fn with_nullable(self, nullable: bool) -> Self
pub fn with_nullable(self, nullable: bool) -> Self
Set whether the column is nullable.
Sourcepub fn with_max_length(self, max_length: u32) -> Self
pub fn with_max_length(self, max_length: u32) -> Self
Set the maximum length.
Sourcepub fn with_precision_scale(self, precision: u8, scale: u8) -> Self
pub fn with_precision_scale(self, precision: u8, scale: u8) -> Self
Set precision and scale for numeric types.
Sourcepub fn with_collation(self, collation: Collation) -> Self
pub fn with_collation(self, collation: Collation) -> Self
Set the collation for string types.
Used for proper encoding/decoding of non-Unicode string data (VARCHAR, CHAR, TEXT).
Sourcepub fn encoding_name(&self) -> &'static str
pub fn encoding_name(&self) -> &'static str
Get the encoding name for this column’s collation.
Returns the name of the character encoding used for this column’s data, or “unknown” if the collation is not set or the encoding feature is disabled.
§Examples
"Shift_JIS"- Japanese encoding (LCID 0x0411)"GB18030"- Simplified Chinese (LCID 0x0804)"UTF-8"- SQL Server 2019+ UTF-8 collation"windows-1252"- Latin/Western European (LCID 0x0409)"unknown"- No collation or unsupported encoding
Sourcepub fn is_utf8_collation(&self) -> bool
pub fn is_utf8_collation(&self) -> bool
Check if this column uses UTF-8 encoding.
Returns true if the column has a SQL Server 2019+ UTF-8 collation,
which is indicated by bit 27 (0x0800_0000) being set in the LCID.
Sourcepub fn to_type_info(&self) -> TypeInfo
pub fn to_type_info(&self) -> TypeInfo
Convert column metadata to TDS TypeInfo for decoding.
Maps type names to TDS type IDs and constructs appropriate TypeInfo.