pub struct WithDataType<T> {
    pub value: T,
    pub data_type: DataType,
}
Expand description

Annotates an instance of an inner type with an SQL Data type in order to indicate how it should be bound as a parameter to an SQL Statement.

Example

use odbc_api::{Environment, ConnectionOptions, DataType, parameter::WithDataType};

let env = Environment::new()?;

let mut conn = env.connect(
    "YourDatabase", "SA", "My@Test@Password1",
    ConnectionOptions::default()
)?;
// Bind year as VARCHAR(4) rather than integer.
let year = WithDataType{
   value: 1980,
   data_type: DataType::Varchar {length: 4}
};
if let Some(cursor) = conn.execute("SELECT year, name FROM Birthdays WHERE year > ?;", &year)? {
    // Use cursor to process query results.
}

Can also be used to wrap crate::sys::Timestamp so they implement OutputParameter.

let mut ts = WithDataType {
    value: Timestamp::default(),
    data_type: DataType::Timestamp { precision: 0 },
};
connection.execute(
    "INSERT INTO Posts (text, timestamps) VALUES (?,?)",
    (&"Hello".into_parameter(), &ts.into_parameter())
);

Fields§

§value: T

Value to wrap with a Data Type. Should implement crate::handles::CData, to be useful.

§data_type: DataType

The SQL type this value is supposed to map onto. What exactly happens with this information is up to the ODBC driver in use.

Trait Implementations§

source§

impl<'a, T> BoundInputSlice<'a> for WithDataType<T>where T: BoundInputSlice<'a>,

§

type SliceMut = <T as BoundInputSlice<'a>>::SliceMut

Intended to allow for modifying buffer contents, while leaving the bound parameter buffers valid.
source§

unsafe fn as_view_mut( &'a mut self, parameter_index: u16, stmt: StatementRef<'a> ) -> Self::SliceMut

Obtain a mutable view on a parameter buffer in order to change the parameter value(s) submitted when executing the statement. Read more
source§

impl<T> CData for WithDataType<T>where T: CData,

source§

fn cdata_type(&self) -> CDataType

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.
source§

fn indicator_ptr(&self) -> *const isize

Indicates the length of variable sized types. May be zero for fixed sized types. Used to determine the size or existence of input parameters.
source§

fn value_ptr(&self) -> *const c_void

Pointer to a value corresponding to the one described by cdata_type.
source§

fn buffer_length(&self) -> isize

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.
source§

impl<T> CDataMut for WithDataType<T>where T: CDataMut,

source§

fn mut_indicator_ptr(&mut self) -> *mut isize

Indicates the length of variable sized types. May be zero for fixed sized types.
source§

fn mut_value_ptr(&mut self) -> *mut c_void

Pointer to a value corresponding to the one described by cdata_type.
source§

impl<T> ColumnBuffer for WithDataType<T>where T: ColumnBuffer,

§

type View<'a> where T: 'a = <T as ColumnBuffer>::View<'a>

Immutable view on the column data. Used in safe abstractions. User must not be able to access uninitialized or invalid memory of the buffer through this interface.
source§

fn view(&self, valid_rows: usize) -> T::View<'_>

Num rows may not exceed the actually amount of valid num_rows filled be the ODBC API. The column buffer does not know how many elements were in the last row group, and therefore can not guarantee the accessed element to be valid and in a defined state. It also can not panic on accessing an undefined element.
source§

fn fill_default(&mut self, from: usize, to: usize)

Fills the column with the default representation of values, between from and to index.
source§

fn capacity(&self) -> usize

Current capacity of the column
source§

fn has_truncated_values(&self, num_rows: usize) -> bool

true if any value is truncated in the range [0, num_rows). Read more
source§

impl<T: Debug> Debug for WithDataType<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> HasDataType for WithDataType<T>

source§

fn data_type(&self) -> DataType

The SQL data as which the parameter is bound to ODBC.
source§

impl<T> CElement for WithDataType<T>where T: CElement,

source§

impl<T> OutputParameter for WithDataType<T>where T: Pod,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for WithDataType<T>where T: RefUnwindSafe,

§

impl<T> Send for WithDataType<T>where T: Send,

§

impl<T> Sync for WithDataType<T>where T: Sync,

§

impl<T> Unpin for WithDataType<T>where T: Unpin,

§

impl<T> UnwindSafe for WithDataType<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> InputParameter for Twhere T: CElement + HasDataType,