Skip to content

Commit

Permalink
added flag for PIPES_AS_CONCAT connection setting for MySQL to fix #2034
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustut authored Aug 11, 2022
1 parent 373b121 commit ca74b0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sqlx-core/src/mysql/options/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};"#,
Expand Down
12 changes: 12 additions & 0 deletions sqlx-core/src/mysql/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub struct MySqlConnectOptions {
pub(crate) charset: String,
pub(crate) collation: Option<String>,
pub(crate) log_settings: LogSettings,
pub(crate) pipes_as_concat: bool,
}

impl Default for MySqlConnectOptions {
Expand All @@ -89,6 +90,7 @@ impl MySqlConnectOptions {
ssl_ca: None,
statement_cache_capacity: 100,
log_settings: Default::default(),
pipes_as_concat: true,
}
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit ca74b0c

Please sign in to comment.