From f0b30e95267b1a02f11b5d74fae818f4eb474079 Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Wed, 19 Oct 2022 11:09:09 +0100 Subject: [PATCH] =?UTF-8?q?Format=20strings=20with=20`=E2=80=99`=20single?= =?UTF-8?q?=20quotes=20if=20string=20does=20not=20contain=20any=20`?= =?UTF-8?q?=E2=80=99`=20characters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/sql/escape.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/sql/escape.rs b/lib/src/sql/escape.rs index 87c8506e..a7347f06 100644 --- a/lib/src/sql/escape.rs +++ b/lib/src/sql/escape.rs @@ -2,6 +2,8 @@ use crate::sql::common::val_u8; use nom::character::is_digit; use std::borrow::Cow; +const SINGLE: char = '\''; + const BRACKETL: char = '⟨'; const BRACKETR: char = '⟩'; const BRACKET_ESC: &str = r#"\⟩"#; @@ -14,7 +16,11 @@ const BACKTICK_ESC: &str = r#"\`"#; #[inline] pub fn escape_str(s: &str) -> String { - format!("{}{}{}", DOUBLE, s, DOUBLE) + if s.contains(SINGLE) { + format!("{}{}{}", DOUBLE, s, DOUBLE) + } else { + format!("{}{}{}", SINGLE, s, SINGLE) + } } #[inline]