@@ -10,6 +10,7 @@ use anyhow::Context;
1010use futures_util:: future:: BoxFuture ;
1111use sqlx:: {
1212 any:: { Any , AnyConnectOptions , AnyKind } ,
13+ odbc:: OdbcConnectOptions ,
1314 pool:: PoolOptions ,
1415 sqlite:: { Function , SqliteConnectOptions , SqliteFunctionCtx } ,
1516 ConnectOptions , Connection , Executor ,
@@ -208,6 +209,9 @@ fn set_custom_connect_options(options: &mut AnyConnectOptions, config: &AppConfi
208209 if let Some ( sqlite_options) = options. as_sqlite_mut ( ) {
209210 set_custom_connect_options_sqlite ( sqlite_options, config) ;
210211 }
212+ if let Some ( odbc_options) = options. as_odbc_mut ( ) {
213+ set_custom_connect_options_odbc ( odbc_options, config) ;
214+ }
211215}
212216
213217fn set_custom_connect_options_sqlite (
@@ -235,13 +239,26 @@ fn make_sqlite_fun(name: &str, f: fn(&str) -> String) -> Function {
235239 } )
236240}
237241
242+ fn set_custom_connect_options_odbc ( odbc_options : & mut OdbcConnectOptions , config : & AppConfig ) {
243+ // Allow fetching very large text fields when using ODBC by removing the max column size limit
244+ let batch_size = config. max_pending_rows . clamp ( 1 , 1024 ) ;
245+ odbc_options. batch_size ( batch_size) ;
246+ log:: trace!( "ODBC batch size set to {batch_size}" ) ;
247+ // Disables ODBC batching, but avoids truncation of large text fields
248+ odbc_options. max_column_size ( None ) ;
249+ }
250+
238251fn set_database_password ( options : & mut AnyConnectOptions , password : & str ) {
239252 if let Some ( opts) = options. as_postgres_mut ( ) {
240253 * opts = take ( opts) . password ( password) ;
241254 } else if let Some ( opts) = options. as_mysql_mut ( ) {
242255 * opts = take ( opts) . password ( password) ;
243256 } else if let Some ( opts) = options. as_mssql_mut ( ) {
244257 * opts = take ( opts) . password ( password) ;
258+ } else if let Some ( _opts) = options. as_odbc_mut ( ) {
259+ log:: warn!(
260+ "Setting a password for an ODBC connection is not supported via separate config; include credentials in the DSN or connection string"
261+ ) ;
245262 } else if let Some ( _opts) = options. as_sqlite_mut ( ) {
246263 log:: warn!( "Setting a password for a SQLite database is not supported" ) ;
247264 } else {
0 commit comments