@@ -947,34 +947,17 @@ async fn it_handles_prepare_statement_errors() -> anyhow::Result<()> {
947947 }
948948
949949 // Test executing prepared SQL with syntax errors
950- match conn
950+ let res = conn
951951 . prepare ( "SELECT idonotexist FROM idonotexist WHERE idonotexist" )
952- . await
953- {
954- Ok ( stmt) => match stmt. query ( ) . fetch_one ( & mut conn) . await {
955- Ok ( _) => panic ! ( "should be an error" ) ,
956- Err ( sqlx_oldapi:: Error :: Database ( err) ) => {
957- assert ! (
958- err. to_string( ) . contains( "idonotexist" ) ,
959- "{:?} should contain 'idonotexist'" ,
960- err
961- ) ;
962- }
963- Err ( err) => {
964- panic ! ( "should be a database error, got {:?}" , err) ;
965- }
966- } ,
967- Err ( sqlx_oldapi:: Error :: Database ( err) ) => {
968- assert ! (
969- err. to_string( ) . to_lowercase( ) . contains( "idonotexist" ) ,
970- "{:?} should contain 'idonotexist'" ,
971- err
972- ) ;
973- }
974- Err ( err) => {
975- panic ! ( "should be an error, got {:?}" , err) ;
976- }
977- }
952+ . await ;
953+ let Err ( sqlx_oldapi:: Error :: Database ( err) ) = res else {
954+ panic ! ( "should be an error, got {:?}" , res) ;
955+ } ;
956+ assert ! (
957+ err. to_string( ) . to_lowercase( ) . contains( "idonotexist" ) ,
958+ "{:?} should contain 'idonotexist'" ,
959+ err
960+ ) ;
978961 Ok ( ( ) )
979962}
980963
@@ -1185,23 +1168,25 @@ async fn it_handles_concurrent_error_scenarios() -> anyhow::Result<()> {
11851168}
11861169
11871170#[ tokio:: test]
1188- async fn it_handles_prepared_statement_with_wrong_parameters ( ) -> anyhow:: Result < ( ) > {
1171+ async fn it_handles_prepared_statement_with_wrong_parameter_count ( ) -> anyhow:: Result < ( ) > {
11891172 let mut conn = new :: < Odbc > ( ) . await ?;
11901173
11911174 // Prepare a statement expecting specific parameter types
1192- let stmt = conn. prepare ( "SELECT ? + ? AS sum " ) . await ?;
1175+ let stmt = conn. prepare ( "SELECT ? AS a, ? as b " ) . await ?;
11931176
11941177 // Test binding incompatible types (if the database is strict about types)
11951178 // Some databases/drivers are permissive, others are strict
1196- let result = stmt
1197- . query ( )
1198- . bind ( "not_a_number" )
1199- . bind ( "also_not_a_number" )
1200- . fetch_one ( & mut conn)
1201- . await ;
1202- // This may or may not error depending on the database's type system
1203- let _ = result;
1204-
1179+ let result = stmt. query ( ) . bind ( 42_i32 ) . fetch_one ( & mut conn) . await ;
1180+ let Err ( sqlx_oldapi:: Error :: Database ( err) ) = result else {
1181+ panic ! ( "should be an error, got {:?}" , result) ;
1182+ } ;
1183+ // https://learn.microsoft.com/en-us/sql/odbc/reference/appendixes/appendix-a-odbc-error-codes?view=sql-server-ver17
1184+ // 07002 -> COUNT field incorrect
1185+ assert ! (
1186+ err. to_string( ) . contains( "07002" ) ,
1187+ "{:?} should contain '07002' (COUNT field incorrect)" ,
1188+ err
1189+ ) ;
12051190 Ok ( ( ) )
12061191}
12071192
0 commit comments