@@ -5,7 +5,9 @@ use futures_channel::oneshot;
55use futures_intrusive:: sync:: Mutex ;
66
77use crate :: error:: Error ;
8- use crate :: odbc:: { OdbcArgumentValue , OdbcColumn , OdbcConnectOptions , OdbcQueryResult , OdbcRow , OdbcTypeInfo } ;
8+ use crate :: odbc:: {
9+ OdbcArgumentValue , OdbcColumn , OdbcConnectOptions , OdbcQueryResult , OdbcRow , OdbcTypeInfo ,
10+ } ;
911use either:: Either ;
1012use odbc_api:: Cursor ;
1113
@@ -232,40 +234,70 @@ impl ConnectionWorker {
232234 } ) ;
233235 }
234236 }
235- while let Ok ( Some ( mut row) ) = cursor. next_row ( ) {
237+ while let Ok ( Some ( mut row) ) = cursor. next_row ( ) {
236238 let mut values: Vec < ( OdbcTypeInfo , Option < Vec < u8 > > ) > =
237239 Vec :: with_capacity ( columns. len ( ) ) ;
238240 for i in 1 ..=columns. len ( ) {
239241 let mut buf = Vec :: new ( ) ;
240- // Try text first, then fallback to binary, then numeric
241- if let Ok ( true ) = row. get_text ( i as u16 , & mut buf) {
242- values. push ( ( OdbcTypeInfo { name : "TEXT" . into ( ) , is_null : false } , Some ( buf) ) ) ;
243- } else if let Ok ( false ) = row. get_text ( i as u16 , & mut buf) {
244- values. push ( ( OdbcTypeInfo { name : "TEXT" . into ( ) , is_null : true } , None ) ) ;
245- } else if let Ok ( bytes) = row. get_binary ( i as u16 ) {
246- values. push ( ( OdbcTypeInfo { name : "BLOB" . into ( ) , is_null : false } , Some ( bytes. unwrap_or_default ( ) ) ) ) ;
247- } else if let Ok ( opt) = row. get_data :: < i64 > ( i as u16 ) {
248- if let Some ( num) = opt {
249- values. push ( ( OdbcTypeInfo { name : "INT" . into ( ) , is_null : false } , Some ( num. to_string ( ) . into_bytes ( ) ) ) ) ;
250- } else {
251- values. push ( ( OdbcTypeInfo { name : "INT" . into ( ) , is_null : true } , None ) ) ;
252- }
253- } else if let Ok ( opt) = row. get_data :: < f64 > ( i as u16 ) {
254- if let Some ( num) = opt {
255- values. push ( ( OdbcTypeInfo { name : "DOUBLE" . into ( ) , is_null : false } , Some ( num. to_string ( ) . into_bytes ( ) ) ) ) ;
242+ // Try text first, then fallback to binary, then numeric
243+ if let Ok ( true ) = row. get_text ( i as u16 , & mut buf) {
244+ values. push ( (
245+ OdbcTypeInfo {
246+ name : "TEXT" . into ( ) ,
247+ is_null : false ,
248+ } ,
249+ Some ( buf) ,
250+ ) ) ;
251+ } else if let Ok ( false ) =
252+ row. get_text ( i as u16 , & mut buf)
253+ {
254+ values. push ( (
255+ OdbcTypeInfo {
256+ name : "TEXT" . into ( ) ,
257+ is_null : true ,
258+ } ,
259+ None ,
260+ ) ) ;
256261 } else {
257- values. push ( ( OdbcTypeInfo { name : "DOUBLE" . into ( ) , is_null : true } , None ) ) ;
262+ let mut bin = Vec :: new ( ) ;
263+ match row. get_binary ( i as u16 , & mut bin) {
264+ Ok ( true ) => values. push ( (
265+ OdbcTypeInfo {
266+ name : "BLOB" . into ( ) ,
267+ is_null : false ,
268+ } ,
269+ Some ( bin) ,
270+ ) ) ,
271+ Ok ( false ) => values. push ( (
272+ OdbcTypeInfo {
273+ name : "BLOB" . into ( ) ,
274+ is_null : true ,
275+ } ,
276+ None ,
277+ ) ) ,
278+ Err ( _) => values. push ( (
279+ OdbcTypeInfo {
280+ name : "UNKNOWN" . into ( ) ,
281+ is_null : true ,
282+ } ,
283+ None ,
284+ ) ) ,
285+ }
258286 }
259- } else {
260- values. push ( ( OdbcTypeInfo { name : "UNKNOWN" . into ( ) , is_null : true } , None ) ) ;
261287 }
262- }
263- let _ = tx. send ( Ok ( Either :: Right ( OdbcRow { columns : columns. clone ( ) , values } ) ) ) ;
288+ let _ = tx. send ( Ok ( Either :: Right ( OdbcRow {
289+ columns : columns. clone ( ) ,
290+ values,
291+ } ) ) ) ;
264292 }
265- let _ = tx. send ( Ok ( Either :: Left ( OdbcQueryResult { rows_affected : 0 } ) ) ) ;
293+ let _ = tx. send ( Ok ( Either :: Left ( OdbcQueryResult {
294+ rows_affected : 0 ,
295+ } ) ) ) ;
266296 }
267297 Ok ( None ) => {
268- let _ = tx. send ( Ok ( Either :: Left ( OdbcQueryResult { rows_affected : 0 } ) ) ) ;
298+ let _ = tx. send ( Ok ( Either :: Left ( OdbcQueryResult {
299+ rows_affected : 0 ,
300+ } ) ) ) ;
269301 }
270302 Err ( e) => {
271303 let _ = tx. send ( Err ( Error :: from ( e) ) ) ;
0 commit comments