Skip to content

Commit 0ff092e

Browse files
committed
refactor(odbc): update text length constants and improve buffer handling
This commit modifies the text length constants in the ODBC bridge, changing `MAX_TEXT_LEN` to 4096 and introducing `MIN_TEXT_LEN` as 1024. Additionally, it enhances the handling of various data types by ensuring that the maximum string length is constrained between these new limits, improving the robustness of buffer descriptions.
1 parent 4b5be2b commit 0ff092e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const BATCH_SIZE: usize = 128;
1919
const DEFAULT_TEXT_LEN: usize = 512;
2020
const DEFAULT_BINARY_LEN: usize = 1024;
2121
const DEFAULT_NUMERIC_TEXT_LEN: usize = 128;
22-
const MAX_TEXT_LEN: usize = 1024;
22+
const MIN_TEXT_LEN: usize = 1024;
23+
const MAX_TEXT_LEN: usize = 4096;
2324
const MAX_BINARY_LEN: usize = 1024;
2425

2526
struct ColumnBinding {
@@ -204,14 +205,23 @@ where
204205
length: DEFAULT_BINARY_LEN,
205206
}
206207
}
207-
DataType::Char { .. }
208-
| DataType::WChar { .. }
209-
| DataType::Varchar { .. }
210-
| DataType::WVarchar { .. }
211-
| DataType::LongVarchar { .. }
212-
| DataType::WLongVarchar { .. }
213-
| DataType::Other { .. }
214-
| DataType::Unknown => BufferDesc::Text {
208+
DataType::Char { length }
209+
| DataType::WChar { length }
210+
| DataType::Varchar { length }
211+
| DataType::WVarchar { length }
212+
| DataType::LongVarchar { length }
213+
| DataType::WLongVarchar { length }
214+
| DataType::Other {
215+
column_size: length,
216+
..
217+
} => BufferDesc::Text {
218+
max_str_len: if let Some(length) = length {
219+
std::cmp::max(std::cmp::min(length.get(), MAX_TEXT_LEN), MIN_TEXT_LEN)
220+
} else {
221+
MAX_TEXT_LEN
222+
},
223+
},
224+
DataType::Unknown => BufferDesc::Text {
215225
max_str_len: MAX_TEXT_LEN,
216226
},
217227
DataType::Decimal { .. } | DataType::Numeric { .. } => BufferDesc::Text {

0 commit comments

Comments
 (0)