|
1 | | -use super::decode_column_name; |
| 1 | +use super::describe_column; |
2 | 2 | use crate::error::Error; |
3 | 3 | use crate::odbc::OdbcValueVec; |
4 | 4 | use crate::odbc::{ |
@@ -29,7 +29,7 @@ fn build_bindings<C: Cursor>( |
29 | 29 | let column_count = cursor.num_result_cols().unwrap_or(0); |
30 | 30 | let mut bindings = Vec::with_capacity(column_count as usize); |
31 | 31 | for index in 1..=column_count { |
32 | | - let column = create_column(cursor, index as u16); |
| 32 | + let column = describe_column(cursor, index as u16)?; |
33 | 33 | let nullable = cursor |
34 | 34 | .col_nullability(index as u16) |
35 | 35 | .unwrap_or(Nullability::Unknown) |
@@ -249,20 +249,6 @@ fn send_row(tx: &ExecuteSender, row: OdbcRow) -> Result<(), SendError<ExecuteRes |
249 | 249 | tx.send(Ok(Either::Right(row))) |
250 | 250 | } |
251 | 251 |
|
252 | | -fn create_column<C>(cursor: &mut C, index: u16) -> OdbcColumn |
253 | | -where |
254 | | - C: ResultSetMetadata, |
255 | | -{ |
256 | | - let mut cd = odbc_api::ColumnDescription::default(); |
257 | | - let _ = cursor.describe_col(index, &mut cd); |
258 | | - |
259 | | - OdbcColumn { |
260 | | - name: decode_column_name(cd.name, index), |
261 | | - type_info: OdbcTypeInfo::new(cd.data_type), |
262 | | - ordinal: usize::from(index.checked_sub(1).unwrap()), |
263 | | - } |
264 | | -} |
265 | | - |
266 | 252 | fn map_buffer_desc( |
267 | 253 | type_info: &OdbcTypeInfo, |
268 | 254 | nullable: bool, |
@@ -320,17 +306,18 @@ fn create_column_data(slice: AnySlice<'_>, column: &OdbcColumn) -> Arc<ColumnDat |
320 | 306 | }) |
321 | 307 | } |
322 | 308 |
|
323 | | -fn build_columns_from_cursor<C>(cursor: &mut C) -> Vec<OdbcColumn> |
| 309 | +fn build_columns_from_cursor<C>(cursor: &mut C) -> Result<Vec<OdbcColumn>, Error> |
324 | 310 | where |
325 | 311 | C: ResultSetMetadata, |
326 | 312 | { |
327 | | - let column_count = cursor.num_result_cols().expect("no column count found"); |
328 | | - let column_count = u16::try_from(column_count).expect("invalid column count"); |
| 313 | + let column_count = cursor.num_result_cols()?; |
| 314 | + let column_count = u16::try_from(column_count) |
| 315 | + .map_err(|_| Error::Protocol(format!("ODBC column count {column_count} exceeds u16")))?; |
329 | 316 | let mut columns = Vec::with_capacity(usize::from(column_count)); |
330 | 317 | for index in 1..=column_count { |
331 | | - columns.push(create_column(cursor, index)); |
| 318 | + columns.push(describe_column(cursor, index)?); |
332 | 319 | } |
333 | | - columns |
| 320 | + Ok(columns) |
334 | 321 | } |
335 | 322 |
|
336 | 323 | fn build_column_data_from_values( |
@@ -445,7 +432,7 @@ where |
445 | 432 |
|
446 | 433 | let mut receiver_open = true; |
447 | 434 |
|
448 | | - let columns = build_columns_from_cursor(&mut cursor); |
| 435 | + let columns = build_columns_from_cursor(&mut cursor)?; |
449 | 436 | let column_count = columns.len(); |
450 | 437 |
|
451 | 438 | let col_arc: Arc<[OdbcColumn]> = Arc::from(columns.clone()); |
|
0 commit comments