Enum odbc_api::buffers::BufferKind
source · pub enum BufferKind {
}
Expand description
This class is used together with BufferDescription
to specify the layout of buffers bound to
ODBC cursors and statements.
Variants
Binary
Fields
length: usize
Maximum number of bytes per value.
Variable sized binary buffer, holding up to length
bytes per value.
Text
Fields
max_str_len: usize
Maximum string length. Terminating zero is excluded, i.e. memory for it will be implicitly allocated if required.
Text buffer holding strings with binary length of up to max_str_len
.
If choosing this based on the information in a DataType::Varchar
column it is
recommended to think about an upper bound. E.g. PostgreSQL may return a field size of
several GiB for individual values if a column is specified as TEXT
, or Microsoft SQL
Server may return 0
for a column of type VARCHAR(max)
. In such situations, if values are
truly that large, bulk fetching data is not recommended, but streaming individual fields one
by one. Usually though, the actual cells of the table in the database contain much shorter
value. The best thing todo is to adapt the database schema to better reflect the actual size
of the values. Lacking control over the database schema, you can always choose a smaller
buffer size than initializing the buffer in disagreement with the database schema.
WText
Fields
max_str_len: usize
Maximum string length. Terminating zero is excluded, i.e. memory for it will be implicitly allocated if required.
UTF-16 encoded text buffer holding strings with length of up to max_str_len
. Length is in
terms of 2-Byte characters.
F64
64 bit floating point
F32
32 bit floating point
Date
Describes a buffer holding crate::sys::Date
values.
Time
Describes a buffer holding crate::sys::Time
values.
Timestamp
Describes a buffer holding crate::sys::Timestamp
values.
I8
Signed 8 Bit integer
I16
Signed 16 Bit integer
I32
Signed 32 Bit integer
I64
Signed 64 Bit integer
U8
Unsigned 8 Bit integer
Bit
Can either be zero or one
Implementations
sourceimpl BufferKind
impl BufferKind
sourcepub fn from_data_type(data_type: DataType) -> Option<Self>
pub fn from_data_type(data_type: DataType) -> Option<Self>
Describe a buffer which fits best the SQL Data Type.
use odbc_api::{DataType, buffers::BufferKind};
assert_eq!(BufferKind::from_data_type(DataType::Unknown), None);
assert_eq!(
BufferKind::from_data_type(DataType::Numeric { precision: 2, scale: 0 }),
Some(BufferKind::I8)
);
assert_eq!(
BufferKind::from_data_type(DataType::Numeric { precision: 9, scale: 0 }),
Some(BufferKind::I32)
);
assert_eq!(
BufferKind::from_data_type(DataType::Numeric { precision: 18, scale: 0 }),
Some(BufferKind::I64)
);
assert_eq!(
BufferKind::from_data_type(DataType::Numeric { precision: 20, scale: 5 }),
Some(BufferKind::Text { max_str_len: 20 + 2 })
);
assert_eq!(
BufferKind::from_data_type(DataType::Varchar { length: 42 }),
Some(BufferKind::Text { max_str_len: 42 })
);
// We do not care about the encoding in the datasource. WVarchar is mapped to `Text`, too
// (instead of `WText`).
assert_eq!(
BufferKind::from_data_type(DataType::WVarchar { length: 42 }),
Some(BufferKind::Text { max_str_len: 42 })
);
assert_eq!(
BufferKind::from_data_type(DataType::BigInt),
Some(BufferKind::I64)
);
assert_eq!(
BufferKind::from_data_type(DataType::Integer),
Some(BufferKind::I32)
);
assert_eq!(
BufferKind::from_data_type(DataType::SmallInt),
Some(BufferKind::I16)
);
assert_eq!(
BufferKind::from_data_type(DataType::TinyInt),
Some(BufferKind::I8)
);
assert_eq!(
BufferKind::from_data_type(DataType::Float { precision : 24 }),
Some(BufferKind::F32)
);
assert_eq!(
BufferKind::from_data_type(DataType::Float { precision : 53 }),
Some(BufferKind::F64)
);
assert_eq!(
BufferKind::from_data_type(DataType::Double),
Some(BufferKind::F64)
);
assert_eq!(
BufferKind::from_data_type(DataType::Date),
Some(BufferKind::Date)
);
assert_eq!(
BufferKind::from_data_type(DataType::Time { precision: 0 }),
Some(BufferKind::Time)
);
assert_eq!(
BufferKind::from_data_type(DataType::Bit),
Some(BufferKind::Bit)
);
assert_eq!(
BufferKind::from_data_type(DataType::Time { precision: 3 }),
Some(BufferKind::Text { max_str_len: 12 })
);
assert_eq!(
BufferKind::from_data_type(DataType::Timestamp { precision: 3 }),
Some(BufferKind::Timestamp)
);
Trait Implementations
sourceimpl Clone for BufferKind
impl Clone for BufferKind
sourcefn clone(&self) -> BufferKind
fn clone(&self) -> BufferKind
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more