odbc_api::parameter

Struct WithDataType

Source
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};
use std::num::NonZeroUsize;

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: NonZeroUsize::new(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>,

Source§

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> CElement for WithDataType<T>
where T: CElement,

Source§

fn assert_completness(&self)

Must panic if the parameter is not complete. I.e. the indicator of a variable length parameter indicates a value larger than what is present in the value buffer. Read more
Source§

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

Source§

type View<'a> = <T as ColumnBuffer>::View<'a> where T: '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 actual amount of valid num_rows filled by 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) -> Option<Indicator>

Some 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> OutputParameter for WithDataType<T>
where T: Pod,

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoParameter for T
where T: InputParameter,

Source§

impl<T> ParameterCollection for T
where T: InputParameterCollection + ?Sized,

Source§

fn parameter_set_size(&self) -> usize

Number of values per parameter in the collection. This can be different from the maximum batch size a buffer may be able to hold. Returning 0 will cause the the query not to be executed.
Source§

unsafe fn bind_parameters_to( &mut self, stmt: &mut impl Statement, ) -> Result<(), Error>

Bind the parameters to a statement Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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