Skip to content

Commit ca74b0c

Browse files
authored
added flag for PIPES_AS_CONCAT connection setting for MySQL to fix #2034 (#2046)
1 parent 373b121 commit ca74b0c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

sqlx-core/src/mysql/options/connect.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ impl ConnectOptions for MySqlConnectOptions {
4242
// https://mathiasbynens.be/notes/mysql-utf8mb4
4343

4444
let mut options = String::new();
45-
options.push_str(r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),"#);
45+
if self.pipes_as_concat {
46+
options.push_str(r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',PIPES_AS_CONCAT,NO_ENGINE_SUBSTITUTION')),"#);
47+
} else {
48+
options.push_str(
49+
r#"SET sql_mode=(SELECT CONCAT(@@sql_mode, ',NO_ENGINE_SUBSTITUTION')),"#,
50+
);
51+
}
4652
options.push_str(r#"time_zone='+00:00',"#);
4753
options.push_str(&format!(
4854
r#"NAMES {} COLLATE {};"#,

sqlx-core/src/mysql/options/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub struct MySqlConnectOptions {
6565
pub(crate) charset: String,
6666
pub(crate) collation: Option<String>,
6767
pub(crate) log_settings: LogSettings,
68+
pub(crate) pipes_as_concat: bool,
6869
}
6970

7071
impl Default for MySqlConnectOptions {
@@ -89,6 +90,7 @@ impl MySqlConnectOptions {
8990
ssl_ca: None,
9091
statement_cache_capacity: 100,
9192
log_settings: Default::default(),
93+
pipes_as_concat: true,
9294
}
9395
}
9496

@@ -212,4 +214,14 @@ impl MySqlConnectOptions {
212214
self.collation = Some(collation.to_owned());
213215
self
214216
}
217+
218+
/// Sets the flag that enables or disables the `PIPES_AS_CONCAT` connection setting
219+
///
220+
/// The default value is set to true, but some MySql databases such as PlanetScale
221+
/// error out with this connection setting so it needs to be set false in such
222+
/// cases.
223+
pub fn pipes_as_concat(mut self, flag_val: bool) -> Self {
224+
self.pipes_as_concat = flag_val;
225+
self
226+
}
215227
}

0 commit comments

Comments
 (0)