Struct odbc_api::buffers::TextColumn[][src]

pub struct TextColumn<C> { /* fields omitted */ }
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

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.

Bytes of string at the specified position. 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.

Maximum length of elements

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

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.

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.

Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input during insertion. All values in the buffer will be set to NULL.

Parameters
  • new_max_len: New maximum string length without terminating zero.

Appends a new element to the column buffer. Rebinds the buffer to increase maximum string length should text be to large.

Parameters
  • index: Zero based index of the new row position. Must be equal to the number of rows currently in the buffer.
  • text: Text to store without terminating zero.

Iterator over the first num_rows values of a text column.

Safety

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

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.

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();
}

Fills the column with NULL, between From and To

A writer able to fill the first n elements of the buffer, from an iterator.

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.