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 54 55 56
//! Implementation and types required to bind arguments to ODBC parameters.
use odbc_sys::CDataType;
use std::ffi::c_void;
use crate::DataType;
/// Provides description of C type layout and pointers to it. Used to bind and buffers to ODBC
/// statements.
pub unsafe trait CData {
    /// The identifier of the C data type of the value buffer. When it is retrieving data from the
    /// data source with `fetch`, the driver converts the data to this type. When it sends data to
    /// the source, the driver converts the data from this type.
    fn cdata_type(&self) -> CDataType;
    /// Indicates the length of variable sized types. May be zero for fixed sized types.
    fn indicator_ptr(&self) -> *const isize;
    /// Pointer to a value corresponding to the one described by `cdata_type`.
    fn value_ptr(&self) -> *const c_void;
    /// Maximum length of the type in bytes (not characters). It is required to index values in
    /// bound buffers, if more than one parameter is bound. Can be set to zero for types not bound
    /// as parameter arrays, i.e. `CStr`.
    fn buffer_length(&self) -> isize;
}
/// A type which can be bound mutably to ODBC.
pub unsafe trait CDataMut: CData {
    /// Indicates the length of variable sized types. May be zero for fixed sized types.
    fn mut_indicator_ptr(&mut self) -> *mut isize;
    /// Pointer to a value corresponding to the one described by `cdata_type`.
    fn mut_value_ptr(&mut self) -> *mut c_void;
}
/// Stream which can be bound as in input parameter to a statement in order to provide the actual
/// data at statement execution time, rather than preallocated buffers.
pub unsafe trait DelayedInput {
    /// Then streaming data to the "data source" the driver converts the data from this type.
    fn cdata_type(&self) -> CDataType;
    /// Either [`odbc_sys::DATA_AT_EXEC`] or the result of [`odbc_sys::len_data_at_exec`].
    fn indicator_ptr(&self) -> *const isize;
    /// Pointer to the stream or an application defined value identifying the stream.
    fn stream_ptr(&mut self) -> *mut c_void;
}
/// Can be bound to a single placeholder in an SQL statement.
///
/// Users usually will not utilize this trait directly.
pub unsafe trait HasDataType {
    /// The SQL data as which the parameter is bound to ODBC.
    fn data_type(&self) -> DataType;
}