mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
This commit is contained in:
parent
373b121a03
commit
ca74b0c141
2 changed files with 19 additions and 1 deletions
|
@ -42,7 +42,13 @@ impl ConnectOptions for MySqlConnectOptions {
|
|||
// https://mathiasbynens.be/notes/mysql-utf8mb4
|
||||
|
||||
let mut options = String::new();
|
||||
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 {};"#,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue