From 65c1d7bf08097a7537a9b4ecb4324bf568d28cdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Sat, 21 Sep 2024 19:41:09 +0000 Subject: [PATCH] test --- src/sql/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sql/mod.rs b/src/sql/mod.rs index ecbc37b..d7a37d9 100644 --- a/src/sql/mod.rs +++ b/src/sql/mod.rs @@ -85,12 +85,16 @@ impl SqlBuilder { } } - pub(crate) fn append(&mut self, part: &str) { + pub(crate) fn append(&mut self, suffix: &str) { let Self::InProgress(parts) = self else { return; }; - parts.push(Part::Text(part.to_string())); + if let Some(Part::Text(text)) = parts.last_mut() { + text.push_str(suffix); + } else { + parts.push(Part::Text(suffix.to_string())); + } } pub(crate) fn finish(mut self) -> Result { @@ -188,6 +192,12 @@ mod tests { ); } + #[test] + fn question_escape() { + let sql = SqlBuilder::new("SELECT 1 FROM test WHERE a IN 'a??b'"); + assert_eq!(sql.finish().unwrap(), r"SELECT 1 FROM test WHERE a IN 'a?b'"); + } + #[test] fn option_as_null() { let mut sql = SqlBuilder::new("SELECT 1 FROM test WHERE a = ?");