Struct odbc_api::buffers::TextColumnSliceMut
source · pub struct TextColumnSliceMut<'a, C> { /* private fields */ }Expand description
A view to a mutable array parameter text buffer, which allows for filling the buffer with values.
Implementations§
source§impl<'a, C> TextColumnSliceMut<'a, C>where
C: Default + Copy,
impl<'a, C> TextColumnSliceMut<'a, C>where
C: Default + Copy,
sourcepub fn set_cell(&mut self, row_index: usize, element: Option<&[C]>)
pub fn set_cell(&mut self, row_index: usize, element: Option<&[C]>)
Sets the value of the buffer at index at Null or the specified binary Text. This method will
panic on out of bounds index, or if input holds a text which is larger than the maximum
allowed element length. element must be specified without the terminating zero.
sourcepub fn ensure_max_element_length(
&mut self,
element_length: usize,
num_rows_to_copy: usize
) -> Result<(), Error>where
TextColumn<C>: HasDataType + CData,
pub fn ensure_max_element_length(
&mut self,
element_length: usize,
num_rows_to_copy: usize
) -> Result<(), Error>where
TextColumn<C>: HasDataType + CData,
Ensures that the buffer is large enough to hold elements of element_length. Does nothing
if the buffer is already large enough. Otherwise it will reallocate and rebind the buffer.
The first num_rows_to_copy_elements will be copied from the old value buffer to the new
one. This makes this an extremly expensive operation.
Examples found in repository?
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
pub fn append<'b>(
&mut self,
mut row: impl Iterator<Item = Option<&'b [u8]>>,
) -> Result<(), Error>
where
S: AsStatementRef,
{
if self.capacity == self.parameter_set_size {
panic!("Trying to insert elements into TextRowSet beyond batch size.")
}
let mut col_index = 1;
for column in &mut self.parameters {
let text = row.next().expect(
"Row passed to TextRowSet::append must contain one element for each column.",
);
if let Some(text) = text {
unsafe {
column
.as_view_mut(col_index, self.statement.as_stmt_ref())
.ensure_max_element_length(text.len(), self.parameter_set_size)?;
}
column.set_value(self.parameter_set_size, Some(text));
} else {
column.set_value(self.parameter_set_size, None);
}
col_index += 1;
}
self.parameter_set_size += 1;
Ok(())
}sourcepub fn set_mut(&mut self, index: usize, length: usize) -> &mut [C] ⓘ
pub fn set_mut(&mut self, index: usize, length: usize) -> &mut [C] ⓘ
Can be used to set a value at a specific row index without performing a memcopy on an input slice and instead provides direct access to the underlying buffer.
In situations there the memcopy can not be avoided anyway Self::set_cell is likely to
be more convenient. This method is very useful if you want to write! a string value to the
buffer and the binary (!) length of the formatted string is known upfront.
Example: Write timestamp to text column.
use odbc_api::buffers::TextColumnSliceMut;
use std::io::Write;
/// Writes times formatted as hh::mm::ss.fff
fn write_time(
col: &mut TextColumnSliceMut<u8>,
index: usize,
hours: u8,
minutes: u8,
seconds: u8,
milliseconds: u16)
{
write!(
col.set_mut(index, 12),
"{:02}:{:02}:{:02}.{:03}",
hours, minutes, seconds, milliseconds
).unwrap();
}