File tree Expand file tree Collapse file tree 3 files changed +35
-3
lines changed
Expand file tree Collapse file tree 3 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,29 @@ impl<'r> Decode<'r, Odbc> for Uuid {
3838 if let Some ( bytes) = value. blob {
3939 if bytes. len ( ) == 16 {
4040 return Ok ( Uuid :: from_bytes ( bytes. try_into ( ) ?) ) ;
41+ } else if bytes. len ( ) == 128 {
42+ // Each byte is ASCII '0' or '1' representing a bit
43+ let mut uuid_bytes = [ 0u8 ; 16 ] ;
44+ for ( i, chunk) in bytes. chunks ( 8 ) . enumerate ( ) {
45+ if i >= 16 {
46+ break ;
47+ }
48+ let mut byte_val = 0u8 ;
49+ for ( j, & bit_byte) in chunk. iter ( ) . enumerate ( ) {
50+ if bit_byte == 49 {
51+ // ASCII '1'
52+ byte_val |= 1 << ( 7 - j) ;
53+ }
54+ }
55+ uuid_bytes[ i] = byte_val;
56+ }
57+ return Ok ( Uuid :: from_bytes ( uuid_bytes) ) ;
4158 }
4259 // Some drivers may return UUIDs as ASCII/UTF-8 bytes
4360 let s = std:: str:: from_utf8 ( bytes) ?. trim ( ) ;
44- return Ok ( Uuid :: from_str ( s) ?) ;
61+ return Ok ( Uuid :: from_str ( s) . map_err ( |e| format ! ( "Invalid UUID: {}, error: {}" , s , e ) ) ?) ;
4562 }
4663 let s = <String as Decode < ' r , Odbc > >:: decode ( value) ?;
47- Ok ( Uuid :: from_str ( s. trim ( ) ) ?)
64+ Ok ( Uuid :: from_str ( s. trim ( ) ) . map_err ( |e| format ! ( "Invalid UUID: {}, error: {}" , s , e ) ) ?)
4865 }
4966}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::odbc::{Odbc, OdbcTypeInfo};
22use crate :: value:: { Value , ValueRef } ;
33use std:: borrow:: Cow ;
44
5+ #[ derive( Debug ) ]
56pub struct OdbcValueRef < ' r > {
67 pub ( crate ) type_info : OdbcTypeInfo ,
78 pub ( crate ) is_null : bool ,
Original file line number Diff line number Diff line change @@ -140,7 +140,21 @@ async fn it_pings() -> anyhow::Result<()> {
140140}
141141
142142#[ sqlx_macros:: test]
143- async fn it_executes_with_pool ( ) -> anyhow:: Result < ( ) > {
143+ async fn it_executes_one_statement_with_pool ( ) -> anyhow:: Result < ( ) > {
144+ let pool = sqlx_test:: pool :: < Any > ( ) . await ?;
145+
146+ let rows = pool. fetch_all ( "SELECT 1" ) . await ?;
147+
148+ assert_eq ! ( rows. len( ) , 1 ) ;
149+ assert_eq ! ( rows[ 0 ] . try_get:: <u16 , _>( 0 ) ?, 1 ) ;
150+
151+ Ok ( ( ) )
152+ }
153+
154+ /// ODBC does not support multiple statements in a single query
155+ #[ cfg( not( feature = "odbc" ) ) ]
156+ #[ sqlx_macros:: test]
157+ async fn it_executes_two_statements_with_pool ( ) -> anyhow:: Result < ( ) > {
144158 let pool = sqlx_test:: pool :: < Any > ( ) . await ?;
145159
146160 let rows = pool. fetch_all ( "SELECT 1; SElECT 2" ) . await ?;
You can’t perform that action at this time.
0 commit comments