Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/webserver/database/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use anyhow::Context;
use futures_util::future::BoxFuture;
use sqlx::{
any::{Any, AnyConnectOptions, AnyKind},
odbc::OdbcConnectOptions,
pool::PoolOptions,
sqlite::{Function, SqliteConnectOptions, SqliteFunctionCtx},
ConnectOptions, Connection, Executor,
Expand Down Expand Up @@ -208,6 +209,9 @@ fn set_custom_connect_options(options: &mut AnyConnectOptions, config: &AppConfi
if let Some(sqlite_options) = options.as_sqlite_mut() {
set_custom_connect_options_sqlite(sqlite_options, config);
}
if let Some(odbc_options) = options.as_odbc_mut() {
set_custom_connect_options_odbc(odbc_options, config);
}
}

fn set_custom_connect_options_sqlite(
Expand Down Expand Up @@ -235,13 +239,26 @@ fn make_sqlite_fun(name: &str, f: fn(&str) -> String) -> Function {
})
}

fn set_custom_connect_options_odbc(odbc_options: &mut OdbcConnectOptions, config: &AppConfig) {
// Allow fetching very large text fields when using ODBC by removing the max column size limit
let batch_size = config.max_pending_rows.clamp(1, 1024);
odbc_options.batch_size(batch_size);
log::trace!("ODBC batch size set to {batch_size}");
// Disables ODBC batching, but avoids truncation of large text fields
odbc_options.max_column_size(None);
}

fn set_database_password(options: &mut AnyConnectOptions, password: &str) {
if let Some(opts) = options.as_postgres_mut() {
*opts = take(opts).password(password);
} else if let Some(opts) = options.as_mysql_mut() {
*opts = take(opts).password(password);
} else if let Some(opts) = options.as_mssql_mut() {
*opts = take(opts).password(password);
} else if let Some(_opts) = options.as_odbc_mut() {
log::warn!(
"Setting a password for an ODBC connection is not supported via separate config; include credentials in the DSN or connection string"
);
} else if let Some(_opts) = options.as_sqlite_mut() {
log::warn!("Setting a password for a SQLite database is not supported");
} else {
Expand Down
Loading