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

This commit is contained in:
Marcus Lee 2022-08-12 05:24:32 +08:00 committed by GitHub
parent 373b121a03
commit ca74b0c141
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -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 {};"#,

View file

@ -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 {
@ -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
}
}