pub enum DataType {
Show 23 variants
Unknown,
Char {
length: usize,
},
WChar {
length: usize,
},
Numeric {
precision: usize,
scale: i16,
},
Decimal {
precision: usize,
scale: i16,
},
Integer,
SmallInt,
Float {
precision: usize,
},
Real,
Double,
Varchar {
length: usize,
},
WVarchar {
length: usize,
},
LongVarchar {
length: usize,
},
LongVarbinary {
length: usize,
},
Date,
Time {
precision: i16,
},
Timestamp {
precision: i16,
},
BigInt,
TinyInt,
Bit,
Varbinary {
length: usize,
},
Binary {
length: usize,
},
Other {
data_type: SqlDataType,
column_size: usize,
decimal_digits: i16,
},
}
Expand description
Enumeration over valid SQL Data Types supported by ODBC
Variants
Unknown
The type is not known.
Char
Fields
length: usize
Column size in characters (excluding terminating zero).
Char(n)
. Character string of fixed length.
WChar
Fields
length: usize
Column size in characters (excluding terminating zero).
NChar(n)
. Character string of fixed length.
Numeric
`Numeric(p,s). Signed, exact, numeric value with a precision p and scale s (1 <= p <= 15; s <= p)
Decimal
Decimal(p,s)
. Signed, exact, numeric value with a precision of at least p and scale s.
The maximum precision is driver-defined. (1 <= p <= 15; s <= p)
Integer
Integer
. 32 Bit Integer
SmallInt
Smallint
. 16 Bit Integer
Float
Fields
precision: usize
Float(p)
. Signed, approximate, numeric value with a binary precision of at least p. The
maximum precision is driver-defined.
Depending on the implementation binary precision is either 24 (f32
) or 53 (f64
).
Real
Real
. Signed, approximate, numeric value with a binary precision 24 (zero or absolute
value 10^-38] to 10^38).
Double
Double Precision
. Signed, approximate, numeric value with a binary precision 53 (zero or
absolute value 10^-308 to 10^308).
Varchar
Fields
length: usize
Maximum length of the character string (excluding terminating zero). Wether this length is to be interpreted as bytes or Codepoints is ambigious and depends on the datasource.
E.g. For Microsoft SQL Server this is the binary length, theras for a MariaDB this refers to codepoints in case of UTF-8 encoding. If you need the binary size query the octet length for that column instead.
To find out how to interpret this value for a particular datasource you can use the
odbcsv
command line tool list-columns
subcommand and query a Varchar column. If the
buffer/octet length matches the column size, you can interpret this as the byte length.
Varchar(n)
. Variable length character string.
WVarchar
Fields
length: usize
Maximum length of the character string (excluding terminating zero).
NVARCHAR(n)
. Variable length character string. Indicates the use of wide character strings
and use of UCS2 encoding on the side of the database.
LongVarchar
Fields
length: usize
Maximum length of the character string (excluding terminating zero). Maximum size depends on the capabilities of the driver and datasource. E.g. its 2^31 - 1 for MSSQL.
TEXT
. Variable length characeter string for long text objects.
LongVarbinary
Fields
length: usize
Maximum length of the binary data. Maximum size depends on the capabilities of the driver and datasource.
BLOB
. Variable length data for long binary objects.
Date
Date
. Year, month, and day fields, conforming to the rules of the Gregorian calendar.
Time
Fields
precision: i16
Number of radix ten digits used to represent the timestamp after the decimal points. E.g. Milliseconds would be represented by precision 3, Microseconds by 6 and Nanoseconds by 9.
Time
. Hour, minute, and second fields, with valid values for hours of 00 to 23, valid
values for minutes of 00 to 59, and valid values for seconds of 00 to 61. Precision p
indicates the seconds precision.
Timestamp
Fields
precision: i16
Number of radix ten digits used to represent the timestamp after the decimal points. E.g. Milliseconds would be represented by precision 3, Microseconds by 6 and Nanoseconds by 9.
Timestamp
. Year, month, day, hour, minute, and second fields, with valid values as
defined for the Date and Time variants.
BigInt
BIGINT
. Exact numeric value with precision 19 (if signed) or 20 (if unsigned) and scale 0
(signed: -2^63 <= n <= 2^63 - 1, unsigned: 0 <= n <= 2^64 - 1). Has no corresponding
type in SQL-92.
TinyInt
TINYINT
. Exact numeric value with precision 3 and scale 0 (signed: -128 <= n <= 127,
unsigned: 0 <= n <= 255)
Bit
BIT
. Single bit binary data.
Varbinary
Fields
length: usize
VARBINARY(n)
. Type for variable sized binary data.
Binary
Fields
length: usize
BINARY(n)
. Type for fixed sized binary data.
Other
Fields
data_type: SqlDataType
Type of the column
column_size: usize
Size of column element
decimal_digits: i16
Decimal digits returned for the column element. Exact meaning if any depends on the
data_type
field.
The driver returned a type, but it is not among the other types of these enumeration. This is a catchall, in case the library is incomplete, or the data source supports custom or non-standard types.
Implementations
sourceimpl DataType
impl DataType
sourcepub fn new(
data_type: SqlDataType,
column_size: usize,
decimal_digits: i16
) -> Self
pub fn new(
data_type: SqlDataType,
column_size: usize,
decimal_digits: i16
) -> Self
This constructor is useful to create an instance of the enumeration using values returned by
ODBC Api calls like SQLDescribeCol
, rather than just initializing a variant directly.
sourcepub fn data_type(&self) -> SqlDataType
pub fn data_type(&self) -> SqlDataType
The associated data_type
discriminator for this variant.
sourcepub fn column_size(&self) -> usize
pub fn column_size(&self) -> usize
Return the column size, as it is required to bind the data type as a parameter. This implies
sourcepub fn decimal_digits(&self) -> i16
pub fn decimal_digits(&self) -> i16
Return the number of decimal digits as required to bind the data type as a parameter.
sourcepub fn display_size(&self) -> Option<usize>
pub fn display_size(&self) -> Option<usize>
The maximum number of characters needed to display data in character form.
See: https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/display-size
sourcepub fn utf8_len(&self) -> Option<usize>
pub fn utf8_len(&self) -> Option<usize>
The maximum length of the UTF-8 representation in bytes.
use odbc_api::DataType;
// Character set data types length is multiplied by four.
assert_eq!(DataType::Varchar { length: 10 }.utf8_len(), Some(40));
assert_eq!(DataType::Char { length: 10 }.utf8_len(), Some(40));
assert_eq!(DataType::WVarchar { length: 10 }.utf8_len(), Some(40));
assert_eq!(DataType::WChar { length: 10 }.utf8_len(), Some(40));
// For other types return value is identical to display size as they are assumed to be
// entirely representable with ASCII characters.
assert_eq!(DataType::Numeric { precision: 10, scale: 3}.utf8_len(), Some(10 + 2));
sourcepub fn utf16_len(&self) -> Option<usize>
pub fn utf16_len(&self) -> Option<usize>
The maximum length of the UTF-16 representation in 2-Byte characters.
use odbc_api::DataType;
// Character set data types length is multiplied by two.
assert_eq!(DataType::Varchar { length: 10 }.utf16_len(), Some(20));
assert_eq!(DataType::Char { length: 10 }.utf16_len(), Some(20));
assert_eq!(DataType::WVarchar { length: 10 }.utf16_len(), Some(20));
assert_eq!(DataType::WChar { length: 10 }.utf16_len(), Some(20));
// For other types return value is identical to display size as they are assumed to be
// entirely representable with ASCII characters.
assert_eq!(DataType::Numeric { precision: 10, scale: 3}.utf16_len(), Some(10 + 2));
Trait Implementations
impl Copy for DataType
impl Eq for DataType
impl StructuralEq for DataType
impl StructuralPartialEq for DataType
Auto Trait Implementations
impl RefUnwindSafe for DataType
impl Send for DataType
impl Sync for DataType
impl Unpin for DataType
impl UnwindSafe for DataType
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more