Struct odbc_api::buffers::ColumnarRowSet[][src]

pub struct ColumnarRowSet { /* fields omitted */ }
Expand description

A columnar buffer intended to be bound with crate::Cursor::bind_buffer in order to obtain results from a cursor.

This buffer is designed to be versatile. It supports a wide variety of usage scenarios. It is efficient in retrieving data, but expensive to allocate, as columns are allocated separately. This is required in order to efficiently allow for rebinding columns, if this buffer is used to provide array input parameters those maximum size is not known in advance.

Most applications should find the overhead negligible, especially if instances are reused.

Implementations

impl ColumnarRowSet[src]

pub fn new(
    max_rows: u32,
    description: impl Iterator<Item = BufferDescription>
) -> Self
[src]

Allocates for each buffer description a buffer large enough to hold max_rows.

pub fn with_column_indices(
    max_rows: u32,
    description: impl Iterator<Item = (u16, BufferDescription)>
) -> Self
[src]

Allows you to pass the buffer descriptions together with a one based column index referring the column, the buffer is supposed to bind to. This allows you also to ignore columns in a result set, by not binding them at all. There is no restriction on the order of column indices passed, but the function will panic, if the indices are not unique.

pub fn column(&self, buffer_index: usize) -> AnyColumnView<'_>[src]

Use this method to gain read access to the actual column data.

Parameters

  • buffer_index: Please note that the buffer index is not identical to the ODBC column index. For once it is zero based. It also indexes the buffer bound, and not the columns of the output result set. This is important, because not every column needs to be bound. Some columns may simply be ignored. That being said, if every column of the output is bound in the buffer, in the same order in which they are enumerated in the result set, the relationship between column index and buffer index is buffer_index = column_index - 1.

pub fn column_mut(&mut self, buffer_index: usize) -> AnyColumnViewMut<'_>[src]

Use this method to gain write access to the actual column data.

Parameters

  • buffer_index: Please note that the buffer index is not identical to the ODBC column index. For once it is zero based. It also indexes the buffer bound, and not the columns of the output result set. This is important, because not every column needs to be bound. Some columns may simply be ignored. That being said, if every column of the output is bound in the buffer, in the same order in which they are enumerated in the result set, the relationship between column index and buffer index is buffer_index = column_index - 1.

Example

This method is intend to be called if using ColumnarRowSet for column wise bulk inserts.

use odbc_api::{
    Connection, Error, IntoParameter,
    buffers::{ColumnarRowSet, BufferDescription, BufferKind, AnyColumnViewMut}
};

fn insert_birth_years(conn: &Connection, names: &[&str], years: &[i16])
    -> Result<(), Error>
{

    // All columns must have equal length.
    assert_eq!(names.len(), years.len());

    // Create a columnar buffer which fits the input parameters.
    let buffer_description = [
        BufferDescription {
            kind: BufferKind::Text { max_str_len: 255 },
            nullable: false,
        },
        BufferDescription {
            kind: BufferKind::I16,
            nullable: false,
        },
    ];
    let mut buffer = ColumnarRowSet::new(
        names.len() as u32,
        buffer_description.iter().copied()
    );

    // Fill the buffer with values column by column
    match buffer.column_mut(0) {
        AnyColumnViewMut::Text(mut col) => {
            col.write(names.iter().map(|s| Some(s.as_bytes())))
        }
        _ => panic!("We know the name column to hold text.")
    }

    match buffer.column_mut(1) {
        AnyColumnViewMut::I16(mut col) => {
            col.copy_from_slice(years)
        }
        _ => panic!("We know the year column to hold i16.")
    }

    conn.execute(
        "INSERT INTO Birthdays (name, year) VALUES (?, ?)",
        &buffer
    )?;
    Ok(())
}

pub fn num_rows(&self) -> usize[src]

Number of valid rows in the buffer.

pub fn set_num_rows(&mut self, num_rows: usize)[src]

Set number of valid rows in the buffer. May not be larger than the batch size. If the specified number should be larger than the number of valid rows currently held by the buffer additional rows with the default value are going to be created.

Trait Implementations

impl ParameterCollection for &ColumnarRowSet[src]

fn parameter_set_size(&self) -> u32[src]

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. Read more

unsafe fn bind_parameters_to(
    self,
    stmt: &mut StatementImpl<'_>
) -> Result<(), Error>
[src]

Safety Read more

impl RowSetBuffer for ColumnarRowSet[src]

fn bind_type(&self) -> u32[src]

Declares the bind type of the Row set buffer. 0 Means a columnar binding is used. Any non zero number is interpreted as the size of a single row in a row wise binding style. Read more

fn row_array_size(&self) -> u32[src]

The batch size for bulk cursors, if retrieving many rows at once.

fn mut_num_fetch_rows(&mut self) -> &mut usize[src]

Mutable reference to the number of fetched rows. Read more

unsafe fn bind_to_cursor(
    &mut self,
    cursor: &mut impl Cursor
) -> Result<(), Error>
[src]

Binds the buffer either column or row wise to the cursor. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.