From ca74b0c141ce026f4642824ba189c5d563e6a05f Mon Sep 17 00:00:00 2001 From: Marcus Lee <59773847+marcustut@users.noreply.github.com> Date: Fri, 12 Aug 2022 05:24:32 +0800 Subject: [PATCH] added flag for PIPES_AS_CONCAT connection setting for MySQL to fix #2034 (#2046) --- sqlx-core/src/mysql/options/connect.rs | 8 +++++++- sqlx-core/src/mysql/options/mod.rs | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/mysql/options/connect.rs b/sqlx-core/src/mysql/options/connect.rs index e722924c..fd59dbbd 100644 --- a/sqlx-core/src/mysql/options/connect.rs +++ b/sqlx-core/src/mysql/options/connect.rs @@ -42,7 +42,13 @@ impl ConnectOptions for MySqlConnectOptions { // https://mathiasbynens.be/notes/mysql-utf8mb4 let mut options = String::new(); - options.push_str(r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),"#); + if self.pipes_as_concat { + options.push_str(r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),"#); + } else { + options.push_str( + r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',NO_ENGINE_SUBSTITUTION')),"#, + ); + } options.push_str(r#"time_zone='+00:00',"#); options.push_str(&format!( r#"NAMES {} COLLATE {};"#, diff --git a/sqlx-core/src/mysql/options/mod.rs b/sqlx-core/src/mysql/options/mod.rs index a8f91c34..5d152c38 100644 --- a/sqlx-core/src/mysql/options/mod.rs +++ b/sqlx-core/src/mysql/options/mod.rs @@ -65,6 +65,7 @@ pub struct MySqlConnectOptions { pub(crate) charset: String, pub(crate) collation: Option, pub(crate) log_settings: LogSettings, + pub(crate) pipes_as_concat: bool, } impl Default for MySqlConnectOptions { @@ -89,6 +90,7 @@ impl MySqlConnectOptions { ssl_ca: None, statement_cache_capacity: 100, log_settings: Default::default(), + pipes_as_concat: true, } } @@ -212,4 +214,14 @@ impl MySqlConnectOptions { self.collation = Some(collation.to_owned()); self } + + /// Sets the flag that enables or disables the `PIPES_AS_CONCAT` connection setting + /// + /// The default value is set to true, but some MySql databases such as PlanetScale + /// error out with this connection setting so it needs to be set false in such + /// cases. + pub fn pipes_as_concat(mut self, flag_val: bool) -> Self { + self.pipes_as_concat = flag_val; + self + } }