diff --git a/odbc-api/src/buffers/any_buffer.rs b/odbc-api/src/buffers/any_buffer.rs index c393b030..f1bfdf84 100644 --- a/odbc-api/src/buffers/any_buffer.rs +++ b/odbc-api/src/buffers/any_buffer.rs @@ -6,7 +6,7 @@ use crate::{ columnar_bulk_inserter::BoundInputSlice, error::TooLargeBufferSize, handles::{CData, CDataMut, HasDataType, StatementRef}, - Bit, DataType, Error, + Bit, DataType, Error, cursor::TruncationDiagnostics, }; use super::{ @@ -633,12 +633,12 @@ unsafe impl ColumnBuffer for AnyBuffer { } } - fn has_truncated_values(&self, num_rows: usize) -> bool { + fn has_truncated_values(&self, num_rows: usize) -> Option { match self { AnyBuffer::Binary(col) => col.has_truncated_values(num_rows), AnyBuffer::Text(col) => col.has_truncated_values(num_rows), AnyBuffer::WText(col) => col.has_truncated_values(num_rows), - _ => false, + _ => None, } } } diff --git a/odbc-api/src/buffers/bin_column.rs b/odbc-api/src/buffers/bin_column.rs index 508f93a7..ea841eec 100644 --- a/odbc-api/src/buffers/bin_column.rs +++ b/odbc-api/src/buffers/bin_column.rs @@ -3,7 +3,7 @@ use crate::{ columnar_bulk_inserter::BoundInputSlice, error::TooLargeBufferSize, handles::{CData, CDataMut, HasDataType, Statement, StatementRef}, - DataType, Error, + DataType, Error, cursor::TruncationDiagnostics, }; use log::debug; @@ -101,17 +101,17 @@ impl BinColumn { } } - /// `true` if any value is truncated in the range [0, num_rows). + /// `Some` if any value is truncated 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. - pub fn has_truncated_values(&self, num_rows: usize) -> bool { + pub fn has_truncated_values(&self, num_rows: usize) -> Option { self.indicators .iter() .copied() .take(num_rows) - .any(|indicator| Indicator::from_isize(indicator).is_truncated(self.max_len)) + .any(|indicator| Indicator::from_isize(indicator).is_truncated(self.max_len)).then_some(TruncationDiagnostics { }) } /// Changes the maximum element length the buffer can hold. This operation is useful if you find @@ -350,12 +350,12 @@ impl<'c> BinColumnView<'c> { } } - /// `true` if any value is truncated in the range [0, num_rows). + /// `Some` if any value is truncated 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. - pub fn has_truncated_values(&self) -> bool { + pub fn has_truncated_values(&self) -> Option { self.col.has_truncated_values(self.num_rows) } } diff --git a/odbc-api/src/buffers/columnar.rs b/odbc-api/src/buffers/columnar.rs index cb591c72..1e3be97c 100644 --- a/odbc-api/src/buffers/columnar.rs +++ b/odbc-api/src/buffers/columnar.rs @@ -107,7 +107,7 @@ where fn has_truncated_values(&self) -> Option { self.columns .iter() - .any(|col_buffer| col_buffer.1.has_truncated_values(*self.num_rows)).then_some(TruncationDiagnostics { }) + .find_map(|col_buffer| col_buffer.1.has_truncated_values(*self.num_rows)) } } @@ -155,12 +155,12 @@ pub unsafe trait ColumnBuffer: CDataMut { /// Current capacity of the column fn capacity(&self) -> usize; - /// `true` if any value is truncated in the range [0, num_rows). + /// `Some` if any value is truncated 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. - fn has_truncated_values(&self, num_rows: usize) -> bool; + fn has_truncated_values(&self, num_rows: usize) -> Option; } unsafe impl ColumnBuffer for WithDataType @@ -181,7 +181,7 @@ where self.value.capacity() } - fn has_truncated_values(&self, num_rows: usize) -> bool { + fn has_truncated_values(&self, num_rows: usize) -> Option { self.value.has_truncated_values(num_rows) } } @@ -424,8 +424,8 @@ where self.len() } - fn has_truncated_values(&self, _num_rows: usize) -> bool { - false + fn has_truncated_values(&self, _num_rows: usize) -> Option { + None } } diff --git a/odbc-api/src/buffers/text_column.rs b/odbc-api/src/buffers/text_column.rs index 145a1a8b..a100eb43 100644 --- a/odbc-api/src/buffers/text_column.rs +++ b/odbc-api/src/buffers/text_column.rs @@ -2,7 +2,7 @@ use crate::{ columnar_bulk_inserter::BoundInputSlice, error::TooLargeBufferSize, handles::{CData, CDataMut, HasDataType, Statement, StatementRef}, - DataType, Error, + DataType, Error, cursor::TruncationDiagnostics, }; use super::{ColumnBuffer, Indicator}; @@ -135,18 +135,18 @@ impl TextColumn { } } - /// `true` if any value is truncated in the range [0, num_rows). + /// `Some` if any value is truncated 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. - pub fn has_truncated_values(&self, num_rows: usize) -> bool { + pub fn has_truncated_values(&self, num_rows: usize) -> Option { let max_bin_length = self.max_str_len * size_of::(); self.indicators .iter() .copied() .take(num_rows) - .any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)) + .any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { }) } /// Changes the maximum string length the buffer can hold. This operation is useful if you find @@ -330,16 +330,13 @@ where self.indicators.len() } - fn has_truncated_values(&self, num_rows: usize) -> bool { + fn has_truncated_values(&self, num_rows: usize) -> Option { let max_bin_length = self.max_str_len * size_of::(); self.indicators .iter() .copied() .take(num_rows) - .any(|indicator| match Indicator::from_isize(indicator) { - Indicator::Null | Indicator::NoTotal => true, - Indicator::Length(length_in_bytes) => max_bin_length < length_in_bytes, - }) + .any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { }) } } @@ -408,12 +405,12 @@ impl<'c, C> TextColumnView<'c, C> { self.col.max_len() } - /// `true` if any value is truncated. + /// `Some` if any value is truncated. /// /// 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. - pub fn has_truncated_values(&self) -> bool { + pub fn has_truncated_values(&self) -> Option { self.col.has_truncated_values(self.num_rows) } } diff --git a/odbc-api/src/cursor.rs b/odbc-api/src/cursor.rs index f01ea7fd..e3bdc69e 100644 --- a/odbc-api/src/cursor.rs +++ b/odbc-api/src/cursor.rs @@ -411,7 +411,6 @@ unsafe impl RowSetBuffer for &mut T { /// Additional information in case of writing a value into too short a buffer. pub struct TruncationDiagnostics { - } /// In order to save on network overhead, it is recommended to use block cursors instead of fetching