odbc_api::buffers

Struct TextColumn

Source
pub struct TextColumn<C> { /* private fields */ }
Expand description

A buffer intended to be bound to a column of a cursor. Elements of the buffer will contain a variable amount of characters up to a maximum string length. Since most SQL types have a string representation this buffer can be bound to a column of almost any type, ODBC driver and driver manager should take care of the conversion. Since elements of this type have variable length an indicator buffer needs to be bound, whether the column is nullable or not, and therefore does not matter for this buffer.

Character type C is intended to be either u8 or u16.

Implementations§

Source§

impl<C> TextColumn<C>

Source

pub fn try_new( batch_size: usize, max_str_len: usize, ) -> Result<Self, TooLargeBufferSize>
where C: Default + Copy,

This will allocate a value and indicator buffer for batch_size elements. Each value may have a maximum length of max_str_len. This implies that max_str_len is increased by one in order to make space for the null terminating zero at the end of strings. Uses a fallible allocation for creating the buffer. In applications often the max_str_len size of the buffer, might be directly inspired by the maximum size of the type, as reported, by ODBC. Which might get exceedingly large for types like VARCHAR(MAX)

Source

pub fn new(batch_size: usize, max_str_len: usize) -> Self
where C: Default + Copy,

This will allocate a value and indicator buffer for batch_size elements. Each value may have a maximum length of max_str_len. This implies that max_str_len is increased by one in order to make space for the null terminating zero at the end of strings. All indicators are set to crate::sys::NULL_DATA by default.

Source

pub fn value_at(&self, row_index: usize) -> Option<&[C]>

Bytes of string at the specified position. Includes interior nuls, but excludes the terminating nul.

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. It will panic however if row_index is larger or equal to the maximum number of elements in the buffer.

Source

pub fn max_len(&self) -> usize

Maximum length of elements

Source

pub fn indicator_at(&self, row_index: usize) -> Indicator

Indicator value at the specified position. Useful to detect truncation of data.

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. It will panic however if row_index is larger or equal to the maximum number of elements in the buffer.

Source

pub fn content_length_at(&self, row_index: usize) -> Option<usize>

Length of value at the specified position. This is different from an indicator as it refers to the length of the value in the buffer, not to the length of the value in the datasource. The two things are different for truncated values.

Source

pub fn has_truncated_values(&self, num_rows: usize) -> Option<Indicator>

Finds an indiactor larger than the maximum element size in the range [0, num_rows).

After fetching data we may want to know if any value has been truncated due to the buffer not being able to hold elements of that size. This method checks the indicator buffer element wise.

Source

pub fn resize_max_str(&mut self, new_max_str_len: usize, num_rows: usize)
where C: Default + Copy,

Changes the maximum string length the buffer can hold. This operation is useful if you find an unexpected large input string during insertion.

This is however costly, as not only does the new buffer have to be allocated, but all values have to copied from the old to the new buffer.

This method could also be used to reduce the maximum string length, which would truncate strings in the process.

This method does not adjust indicator buffers as these might hold values larger than the maximum string length.

§Parameters
  • new_max_str_len: New maximum string length without terminating zero.
  • num_rows: Number of valid rows currently stored in this buffer.
Source

pub fn set_value(&mut self, index: usize, input: Option<&[C]>)
where C: Default + Copy,

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. input must be specified without the terminating zero.

Source

pub fn set_mut(&mut self, index: usize, length: usize) -> &mut [C]
where C: Default,

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_value 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::TextColumn;
use std::io::Write;

/// Writes times formatted as hh::mm::ss.fff
fn write_time(
    col: &mut TextColumn<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();
}
Source

pub fn fill_null(&mut self, from: usize, to: usize)

Fills the column with NULL, between From and To

Source

pub fn raw_value_buffer(&self, num_valid_rows: usize) -> &[C]

Provides access to the raw underlying value buffer. Normal applications should have little reason to call this method. Yet it may be useful for writing bindings which copy directly from the ODBC in memory representation into other kinds of buffers.

The buffer contains the bytes for every non null valid element, padded to the maximum string length. The content of the padding bytes is undefined. Usually ODBC drivers write a terminating zero at the end of each string. For the actual value length call Self::content_length_at. Any element starts at index * (Self::max_len + 1).

Source

pub fn row_capacity(&self) -> usize

The maximum number of rows the TextColumn can hold.

Source§

impl TextColumn<u16>

Source

pub unsafe fn ustr_at(&self, row_index: usize) -> Option<&U16Str>

The string slice at the specified position as U16Str. Includes interior nuls, but excludes the terminating nul.

§Safety

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. It will panic however if row_index is larger or equal to the maximum number of elements in the buffer.

Trait Implementations§

Source§

impl<'a, C: 'static> BoundInputSlice<'a> for TextColumn<C>

Source§

type SliceMut = TextColumnSliceMut<'a, C>

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<C: 'static> ColumnBuffer for TextColumn<C>

Source§

fn capacity(&self) -> usize

Maximum number of text strings this column may hold.

Source§

type View<'a> = TextColumnView<'a, C>

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) -> TextColumnView<'_, C>

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 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<C: Debug> Debug for TextColumn<C>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> Freeze for TextColumn<C>

§

impl<C> RefUnwindSafe for TextColumn<C>
where C: RefUnwindSafe,

§

impl<C> Send for TextColumn<C>
where C: Send,

§

impl<C> Sync for TextColumn<C>
where C: Sync,

§

impl<C> Unpin for TextColumn<C>
where C: Unpin,

§

impl<C> UnwindSafe for TextColumn<C>
where C: 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more