@@ -6,7 +6,8 @@ use sqlx_oldapi::{Column, Connection, Executor, Row, Statement};
66async fn odbc_conn ( ) -> anyhow:: Result < AnyConnection > {
77 let url = std:: env:: var ( "DATABASE_URL" ) . expect ( "DATABASE_URL must be set for ODBC tests" ) ;
88
9- // Ensure the URL starts with "odbc:"
9+ // The "odbc:" prefix is now optional - standard ODBC connection strings
10+ // like "DSN=mydsn" or "Driver={SQL Server};..." are automatically detected
1011 let url = if !url. starts_with ( "odbc:" ) {
1112 format ! ( "odbc:{}" , url)
1213 } else {
@@ -340,3 +341,59 @@ async fn it_matches_any_kind_odbc() -> anyhow::Result<()> {
340341 conn. close ( ) . await ?;
341342 Ok ( ( ) )
342343}
344+
345+ #[ cfg( feature = "odbc" ) ]
346+ #[ sqlx_macros:: test]
347+ async fn it_accepts_standard_odbc_connection_strings ( ) -> anyhow:: Result < ( ) > {
348+ use sqlx_oldapi:: any:: AnyKind ;
349+ use std:: str:: FromStr ;
350+
351+ // Test various standard ODBC connection string formats
352+ let test_cases = vec ! [
353+ "DSN=mydsn" ,
354+ "DSN=mydsn;UID=user;PWD=pass" ,
355+ "Driver={SQL Server};Server=localhost;Database=test" ,
356+ "Driver={ODBC Driver 17 for SQL Server};Server=localhost;Database=test" ,
357+ "FILEDSN=myfile.dsn" ,
358+ "odbc:DSN=mydsn" , // Still support the odbc: prefix
359+ "odbc:Driver={SQL Server};Server=localhost" ,
360+ ] ;
361+
362+ for conn_str in test_cases {
363+ let kind_result = AnyKind :: from_str ( conn_str) ;
364+
365+ // If ODBC feature is enabled, these should parse as ODBC
366+ match kind_result {
367+ Ok ( kind) => assert_eq ! (
368+ kind,
369+ AnyKind :: Odbc ,
370+ "Failed to identify '{}' as ODBC" ,
371+ conn_str
372+ ) ,
373+ Err ( e) => panic ! ( "Failed to parse '{}' as ODBC: {}" , conn_str, e) ,
374+ }
375+ }
376+
377+ // Test non-ODBC connection strings don't match
378+ let non_odbc_cases = vec ! [
379+ "postgres://localhost/db" ,
380+ "mysql://localhost/db" ,
381+ "sqlite:memory:" ,
382+ "random string without equals" ,
383+ ] ;
384+
385+ for conn_str in non_odbc_cases {
386+ let kind_result = AnyKind :: from_str ( conn_str) ;
387+ match kind_result {
388+ Ok ( kind) => assert_ne ! (
389+ kind,
390+ AnyKind :: Odbc ,
391+ "Incorrectly identified '{}' as ODBC" ,
392+ conn_str
393+ ) ,
394+ Err ( _) => { } // Expected for unrecognized formats
395+ }
396+ }
397+
398+ Ok ( ( ) )
399+ }
0 commit comments