Skip to content

Commit

Permalink
add indicator to TruncationDiagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Sep 26, 2023
1 parent 8e6b3fb commit 5017f76
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion odbc-api/src/buffers/any_buffer.rs
Expand Up @@ -4,9 +4,10 @@ use odbc_sys::{CDataType, Date, Time, Timestamp};

use crate::{
columnar_bulk_inserter::BoundInputSlice,
cursor::TruncationDiagnostics,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, StatementRef},
Bit, DataType, Error, cursor::TruncationDiagnostics,
Bit, DataType, Error,
};

use super::{
Expand Down
10 changes: 8 additions & 2 deletions odbc-api/src/buffers/bin_column.rs
@@ -1,9 +1,10 @@
use crate::{
buffers::Indicator,
columnar_bulk_inserter::BoundInputSlice,
cursor::TruncationDiagnostics,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, Statement, StatementRef},
DataType, Error, cursor::TruncationDiagnostics,
DataType, Error,
};

use log::debug;
Expand Down Expand Up @@ -111,7 +112,12 @@ impl BinColumn {
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(self.max_len)).then_some(TruncationDiagnostics { })
.find_map(|indicator| {
let indicator = Indicator::from_isize(indicator);
indicator
.is_truncated(self.max_len)
.then_some(TruncationDiagnostics { indicator })
})
}

/// Changes the maximum element length the buffer can hold. This operation is useful if you find
Expand Down
3 changes: 2 additions & 1 deletion odbc-api/src/buffers/columnar.rs
Expand Up @@ -6,11 +6,12 @@ use std::{

use crate::{
columnar_bulk_inserter::BoundInputSlice,
cursor::TruncationDiagnostics,
fixed_sized::Pod,
handles::{CDataMut, Statement, StatementRef},
parameter::WithDataType,
result_set_metadata::utf8_display_sizes,
Error, ResultSetMetadata, RowSetBuffer, cursor::TruncationDiagnostics,
Error, ResultSetMetadata, RowSetBuffer,
};

use super::{Indicator, TextColumn};
Expand Down
17 changes: 14 additions & 3 deletions odbc-api/src/buffers/text_column.rs
@@ -1,8 +1,9 @@
use crate::{
columnar_bulk_inserter::BoundInputSlice,
cursor::TruncationDiagnostics,
error::TooLargeBufferSize,
handles::{CData, CDataMut, HasDataType, Statement, StatementRef},
DataType, Error, cursor::TruncationDiagnostics,
DataType, Error,
};

use super::{ColumnBuffer, Indicator};
Expand Down Expand Up @@ -146,7 +147,12 @@ impl<C> TextColumn<C> {
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { })
.find_map(|indicator| {
let indicator = Indicator::from_isize(indicator);
indicator
.is_truncated(max_bin_length)
.then_some(TruncationDiagnostics { indicator })
})
}

/// Changes the maximum string length the buffer can hold. This operation is useful if you find
Expand Down Expand Up @@ -336,7 +342,12 @@ where
.iter()
.copied()
.take(num_rows)
.any(|indicator| Indicator::from_isize(indicator).is_truncated(max_bin_length)).then_some(TruncationDiagnostics { })
.find_map(|indicator| {
let indicator = Indicator::from_isize(indicator);
indicator
.is_truncated(max_bin_length)
.then_some(TruncationDiagnostics { indicator })
})
}
}

Expand Down
2 changes: 2 additions & 0 deletions odbc-api/src/cursor.rs
Expand Up @@ -417,6 +417,8 @@ unsafe impl<T: RowSetBuffer> RowSetBuffer for &mut T {

/// Additional information in case of writing a value into too short a buffer.
pub struct TruncationDiagnostics {
/// Size indicator reported by the driver indicating the size of the complete value in the DBMS.
pub indicator: Indicator,
}

/// In order to save on network overhead, it is recommended to use block cursors instead of fetching
Expand Down

0 comments on commit 5017f76

Please sign in to comment.