Struct odbc_api::buffers::BinColumnWriter [−][src]
pub struct BinColumnWriter<'a> { /* fields omitted */ }
Expand description
Fills a binary column buffer with elements from an Iterator. See
crate::buffers::AnyColumnViewMut
Implementations
Fill the binary column with values by consuming the iterator and copying its items into the buffer. It will not extract more items from the iterator than the buffer may hold. This method panics if elements of the iterator are larger than the maximum element length of the 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 element length
Changes the maximum element length the buffer can hold. This operation is useful if you find an unexpected large input 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 element length, which would truncate values in the process.
This method does not adjust indicator buffers as these might hold values larger than the maximum element length.
Parameters
new_max_len
: New maximum element length.num_rows
: Number of valid rows currently stored in this buffer.
Inserts a new element to the column buffer. Rebinds the buffer to increase maximum element
length should the value be larger than the maximum allowed element length. The number of
rows the column buffer can hold stays constant, but during rebind only values before index
would be copied to the new memory location. Therefore this method is intended to be used to
fill the buffer element-wise and in order. Hence the name append
.
Parameters
index
: Zero based index of the new row position. Must be equal to the number of rows currently in the buffer.bytes
: Value to store
Example
ColumnarRowSet, BufferDescription, BufferKind, AnyColumnViewMut, AnyColumnView
};
let desc = BufferDescription {
// Buffer size purposefully chosen too small, so we need to increase the buffer size if we
// encounter larger inputs.
kind: BufferKind::Binary { length: 1 },
nullable: true,
};
// Input values to insert.
let input : [Option<&[u8]>; 5]= [
Some(&[1]),
Some(&[2,3]),
Some(&[4,5,6]),
None,
Some(&[7,8,9,10,11,12]),
];
let mut buffer = ColumnarRowSet::new(input.len(), iter::once(desc));
buffer.set_num_rows(input.len());
if let AnyColumnViewMut::Binary(mut writer) = buffer.column_mut(0) {
for (index, &bytes) in input.iter().enumerate() {
writer.append(index, bytes)
}
} else {
panic!("Expected binary column writer");
}
if let AnyColumnView::Binary(col) = buffer.column(0) {
assert!(col.zip(input.iter().copied()).all(|(expected, actual)| expected == actual))
} else {
panic!("Expected binary column slice");
}