From 2f9b392e0af7a90acb47ada6026b01d182e8eb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=A4=E3=83=BC=E3=83=8E=E3=82=B7=E3=83=A5?= Date: Fri, 13 Dec 2024 22:18:06 +0900 Subject: [PATCH] fix: set transaction mode in single command --- src/driver/sqlx_mysql.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/driver/sqlx_mysql.rs b/src/driver/sqlx_mysql.rs index e1c593b0c..2bd4a3fff 100644 --- a/src/driver/sqlx_mysql.rs +++ b/src/driver/sqlx_mysql.rs @@ -275,18 +275,19 @@ pub(crate) async fn set_transaction_config( isolation_level: Option, access_mode: Option, ) -> 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, };