Ensure ON DUPLICATE KEY UPDATE clause is displayed on INSERT statement (#2474)

This commit is contained in:
Tobie Morgan Hitchcock 2023-08-20 19:16:41 +01:00 committed by GitHub
parent c2e695b897
commit b350f052a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -127,6 +127,9 @@ impl fmt::Display for InsertStatement {
f.write_str(" IGNORE")? f.write_str(" IGNORE")?
} }
write!(f, " INTO {} {}", self.into, self.data)?; write!(f, " INTO {} {}", self.into, self.data)?;
if let Some(ref v) = self.update {
write!(f, " {v}")?
}
if let Some(ref v) = self.output { if let Some(ref v) = self.output {
write!(f, " {v}")? write!(f, " {v}")?
} }
@ -189,4 +192,13 @@ mod tests {
let out = res.unwrap().1; let out = res.unwrap().1;
assert_eq!("INSERT IGNORE INTO test (field) VALUES ($value)", format!("{}", out)) assert_eq!("INSERT IGNORE INTO test (field) VALUES ($value)", format!("{}", out))
} }
#[test]
fn insert_statement_ignore_update() {
let sql = "INSERT IGNORE INTO test (field) VALUES ($value) ON DUPLICATE KEY UPDATE field = $value";
let res = insert(sql);
assert!(res.is_ok());
let out = res.unwrap().1;
assert_eq!("INSERT IGNORE INTO test (field) VALUES ($value) ON DUPLICATE KEY UPDATE field = $value", format!("{}", out))
}
} }