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

added flag for PIPES_AS_CONCAT connection setting for MySQL to fix #2034 #2046

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
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
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
}
}