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

pub struct ColumnarRowSet { /* fields omitted */ }

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]

impl RowSetBuffer for ColumnarRowSet[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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.

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.