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>,
impl<'a, T> BoundInputSlice<'a> for WithDataType<T>where
T: BoundInputSlice<'a>,
Source§type SliceMut = <T as BoundInputSlice<'a>>::SliceMut
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
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,
impl<T> CData for WithDataType<T>where
T: CData,
Source§fn cdata_type(&self) -> CDataType
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
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
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
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,
impl<T> CDataMut for WithDataType<T>where
T: CDataMut,
Source§fn mut_indicator_ptr(&mut self) -> *mut isize
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
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,
impl<T> CElement for WithDataType<T>where
T: CElement,
Source§fn assert_completness(&self)
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,
impl<T> ColumnBuffer for WithDataType<T>where
T: ColumnBuffer,
Source§type View<'a> = <T as ColumnBuffer>::View<'a>
where
T: 'a
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<'_>
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)
fn fill_default(&mut self, from: usize, to: usize)
Fills the column with the default representation of values, between
from
and to
index.Source§impl<T: Debug> Debug for WithDataType<T>
impl<T: Debug> Debug for WithDataType<T>
Source§impl<T> HasDataType for WithDataType<T>
impl<T> HasDataType for WithDataType<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoParameter for Twhere
T: InputParameter,
impl<T> IntoParameter for Twhere
T: InputParameter,
type Parameter = T
fn into_parameter(self) -> <T as IntoParameter>::Parameter
Source§impl<T> ParameterCollection for Twhere
T: InputParameterCollection + ?Sized,
impl<T> ParameterCollection for Twhere
T: InputParameterCollection + ?Sized,
Source§fn parameter_set_size(&self) -> usize
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.