Skip to content

Commit c4b1b8f

Browse files
committed
refactor(odbc): improve binary data length handling in buffer descriptions
This commit modifies the handling of binary data types in the ODBC bridge by adjusting the length constraints for `Binary`, `Varbinary`, and `LongVarbinary`. The new implementation ensures that the length is capped between `MIN_TEXT_LEN` and `MAX_TEXT_LEN`, enhancing the robustness of buffer descriptions.
1 parent 0ff092e commit c4b1b8f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

sqlx-core/src/odbc/connection/odbc_bridge.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const DEFAULT_BINARY_LEN: usize = 1024;
2121
const DEFAULT_NUMERIC_TEXT_LEN: usize = 128;
2222
const MIN_TEXT_LEN: usize = 1024;
2323
const MAX_TEXT_LEN: usize = 4096;
24-
const MAX_BINARY_LEN: usize = 1024;
2524

2625
struct ColumnBinding {
2726
column: OdbcColumn,
@@ -200,11 +199,15 @@ where
200199
DataType::Date => BufferDesc::Date { nullable },
201200
DataType::Time { .. } => BufferDesc::Time { nullable },
202201
DataType::Timestamp { .. } => BufferDesc::Timestamp { nullable },
203-
DataType::Binary { .. } | DataType::Varbinary { .. } | DataType::LongVarbinary { .. } => {
204-
BufferDesc::Binary {
205-
length: DEFAULT_BINARY_LEN,
206-
}
207-
}
202+
DataType::Binary { length }
203+
| DataType::Varbinary { length }
204+
| DataType::LongVarbinary { length } => BufferDesc::Binary {
205+
length: if let Some(length) = length {
206+
std::cmp::max(std::cmp::min(length.get(), MAX_TEXT_LEN), MIN_TEXT_LEN)
207+
} else {
208+
MAX_TEXT_LEN
209+
},
210+
},
208211
DataType::Char { length }
209212
| DataType::WChar { length }
210213
| DataType::Varchar { length }

0 commit comments

Comments
 (0)