Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][MySQL] Isolation level not respected when used with access mode #2450

Merged
merged 1 commit into from
Dec 23, 2024
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: 9 additions & 8 deletions src/driver/sqlx_mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,19 @@ pub(crate) async fn set_transaction_config(
isolation_level: Option<IsolationLevel>,
access_mode: Option<AccessMode>,
) -> Result<(), DbErr> {
let mut settings = Vec::new();

if let Some(isolation_level) = isolation_level {
let stmt = Statement {
sql: format!("SET TRANSACTION ISOLATION LEVEL {isolation_level}"),
values: None,
db_backend: DbBackend::MySql,
};
let query = sqlx_query(&stmt);
conn.execute(query).await.map_err(sqlx_error_to_exec_err)?;
settings.push(format!("ISOLATION LEVEL {isolation_level}"));
}

if let Some(access_mode) = access_mode {
settings.push(access_mode.to_string());
}

if !settings.is_empty() {
let stmt = Statement {
sql: format!("SET TRANSACTION {access_mode}"),
sql: format!("SET TRANSACTION {}", settings.join(", ")),
values: None,
db_backend: DbBackend::MySql,
};
Expand Down
Loading