Skip to content

Commit 5f8cbde

Browse files
cursoragentlovasoa
andcommitted
Refactor: Extract ODBC connection options to a separate function
Co-authored-by: contact <[email protected]>
1 parent ce3d250 commit 5f8cbde

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/webserver/database/connect.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use anyhow::Context;
1010
use futures_util::future::BoxFuture;
1111
use sqlx::{
1212
any::{Any, AnyConnectOptions, AnyKind},
13+
odbc::OdbcConnectOptions,
1314
pool::PoolOptions,
1415
sqlite::{Function, SqliteConnectOptions, SqliteFunctionCtx},
1516
ConnectOptions, Connection, Executor,
@@ -208,10 +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
}
211-
// Allow fetching very large text fields when using ODBC by removing the max column size limit
212-
if let Some(odbc_options) = options.as_odbc_mut() {
213-
*odbc_options = std::mem::take(odbc_options).max_column_size(None);
214-
}
212+
if let Some(odbc_options) = options.as_odbc_mut() {
213+
set_custom_connect_options_odbc(odbc_options, config);
214+
}
215215
}
216216

217217
fn set_custom_connect_options_sqlite(
@@ -239,15 +239,20 @@ fn make_sqlite_fun(name: &str, f: fn(&str) -> String) -> Function {
239239
})
240240
}
241241

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+
*odbc_options = std::mem::take(odbc_options).max_column_size(None);
245+
}
246+
242247
fn set_database_password(options: &mut AnyConnectOptions, password: &str) {
243248
if let Some(opts) = options.as_postgres_mut() {
244249
*opts = take(opts).password(password);
245250
} else if let Some(opts) = options.as_mysql_mut() {
246251
*opts = take(opts).password(password);
247252
} else if let Some(opts) = options.as_mssql_mut() {
248253
*opts = take(opts).password(password);
249-
} else if let Some(_opts) = options.as_odbc_mut() {
250-
log::warn!(
254+
} else if let Some(_opts) = options.as_odbc_mut() {
255+
log::warn!(
251256
"Setting a password for an ODBC connection is not supported via separate config; include credentials in the DSN or connection string"
252257
);
253258
} else if let Some(_opts) = options.as_sqlite_mut() {

0 commit comments

Comments
 (0)