Core: Record the escape style of string values
diff --git a/fuzz/fuzz_seeds/bigquery_1695_decoded_quote.sql b/fuzz/fuzz_seeds/bigquery_1695_decoded_quote.sql new file mode 100644 index 0000000..aa827e3 --- /dev/null +++ b/fuzz/fuzz_seeds/bigquery_1695_decoded_quote.sql
@@ -0,0 +1 @@ +SELECT 'a\'b' \ No newline at end of file
diff --git a/fuzz/fuzz_seeds/mysql_2603_decoded_quote.sql b/fuzz/fuzz_seeds/mysql_2603_decoded_quote.sql new file mode 100644 index 0000000..aa827e3 --- /dev/null +++ b/fuzz/fuzz_seeds/mysql_2603_decoded_quote.sql
@@ -0,0 +1 @@ +SELECT 'a\'b' \ No newline at end of file
diff --git a/fuzz/fuzz_seeds/postgres_2603_adjacent_quotes_roundtrip.sql b/fuzz/fuzz_seeds/postgres_2603_adjacent_quotes_roundtrip.sql new file mode 100644 index 0000000..ab93025 --- /dev/null +++ b/fuzz/fuzz_seeds/postgres_2603_adjacent_quotes_roundtrip.sql
@@ -0,0 +1 @@ +SELECT websearch_to_tsquery('''abc''''def''') \ No newline at end of file
diff --git a/fuzz/fuzz_seeds/postgres_2603_backslash_quote_roundtrip.sql b/fuzz/fuzz_seeds/postgres_2603_backslash_quote_roundtrip.sql new file mode 100644 index 0000000..79e1cd9 --- /dev/null +++ b/fuzz/fuzz_seeds/postgres_2603_backslash_quote_roundtrip.sql
@@ -0,0 +1 @@ +SELECT 'a\''b' \ No newline at end of file
diff --git a/fuzz/fuzz_seeds/postgres_2603_doubled_quote_roundtrip.sql b/fuzz/fuzz_seeds/postgres_2603_doubled_quote_roundtrip.sql new file mode 100644 index 0000000..106e594 --- /dev/null +++ b/fuzz/fuzz_seeds/postgres_2603_doubled_quote_roundtrip.sql
@@ -0,0 +1 @@ +SELECT 'a''''b' \ No newline at end of file
diff --git a/fuzz/fuzz_seeds/sqlite_2603_backslash_quote_roundtrip.sql b/fuzz/fuzz_seeds/sqlite_2603_backslash_quote_roundtrip.sql new file mode 100644 index 0000000..688579c --- /dev/null +++ b/fuzz/fuzz_seeds/sqlite_2603_backslash_quote_roundtrip.sql
@@ -0,0 +1 @@ +SELECT json_valid('" \'' "') \ No newline at end of file
diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 930f7d9..9893158 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs
@@ -128,7 +128,8 @@ pub use self::value::{ escape_double_quote_string, escape_quoted_string, DateTimeField, DollarQuotedString, - NormalizationForm, QuoteDelimitedString, QuoteEscaping, TrimWhereField, Value, ValueWithSpan, + NormalizationForm, QuoteDelimitedString, QuoteEscaping, QuotedString, TrimWhereField, Value, + ValueWithSpan, }; use crate::ast::helpers::key_value_options::KeyValueOptions; @@ -12959,7 +12960,7 @@ fn test_interval_display() { let interval = Expr::Interval(Interval { value: Box::new(Expr::Value( - Value::SingleQuotedString(String::from("123:45.67")).with_empty_span(), + Value::SingleQuotedString(String::from("123:45.67").into()).with_empty_span(), )), leading_field: Some(DateTimeField::Minute), leading_precision: Some(10), @@ -12973,7 +12974,7 @@ let interval = Expr::Interval(Interval { value: Box::new(Expr::Value( - Value::SingleQuotedString(String::from("5")).with_empty_span(), + Value::SingleQuotedString(String::from("5").into()).with_empty_span(), )), leading_field: Some(DateTimeField::Second), leading_precision: Some(1),
diff --git a/src/ast/value.rs b/src/ast/value.rs index 9dabff0..25f393a 100644 --- a/src/ast/value.rs +++ b/src/ast/value.rs
@@ -27,7 +27,7 @@ use bigdecimal::BigDecimal; #[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; +use serde::{ser::SerializeStruct, Deserialize, Serialize}; use crate::{ast::Ident, tokenizer::Span}; #[cfg(feature = "visitor")] @@ -39,7 +39,7 @@ /// ``` /// # use sqlparser::ast::{Value, ValueWithSpan}; /// # use sqlparser::tokenizer::{Location, Span}; -/// let value = Value::SingleQuotedString(String::from("endpoint")); +/// let value = Value::SingleQuotedString(String::from("endpoint").into()); /// // from line 1, column 1 to line 1, column 7 /// let span = Span::new(Location::new(1, 1), Location::new(1, 7)); /// let value_with_span = value.with_span(span); @@ -51,7 +51,7 @@ /// ``` /// # use sqlparser::ast::{Value, ValueWithSpan}; /// # use sqlparser::tokenizer::{Location, Span}; -/// let value = Value::SingleQuotedString(String::from("endpoint")); +/// let value = Value::SingleQuotedString(String::from("endpoint").into()); /// let value_with_span = value.with_empty_span(); /// assert_eq!(value_with_span.span, Span::empty()); /// ``` @@ -60,7 +60,7 @@ /// ``` /// # use sqlparser::ast::{Value, ValueWithSpan}; /// # use sqlparser::tokenizer::{Location, Span}; -/// let value = Value::SingleQuotedString(String::from("endpoint")); +/// let value = Value::SingleQuotedString(String::from("endpoint").into()); /// // converting `Value` to `ValueWithSpan` results in an empty span /// let value_with_span: ValueWithSpan = value.into(); /// assert_eq!(value_with_span.span, Span::empty()); @@ -147,7 +147,7 @@ /// Numeric literal (uses `BigDecimal` when the `bigdecimal` feature is enabled). Number(BigDecimal, bool), /// 'string value' - SingleQuotedString(String), + SingleQuotedString(QuotedString), /// Dollar-quoted string literal, e.g. `$$...$$` or `$tag$...$tag$` (Postgres syntax). DollarQuotedString(DollarQuotedString), /// Triple single quoted strings: Example '''abc''' @@ -165,9 +165,9 @@ /// for more details. UnicodeStringLiteral(String), /// B'string value' - SingleQuotedByteStringLiteral(String), + SingleQuotedByteStringLiteral(QuotedString), /// B"string value" - DoubleQuotedByteStringLiteral(String), + DoubleQuotedByteStringLiteral(QuotedString), /// Triple single quoted literal with byte string prefix. Example `B'''abc'''` /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals) TripleSingleQuotedByteStringLiteral(String), @@ -176,10 +176,10 @@ TripleDoubleQuotedByteStringLiteral(String), /// Single quoted literal with raw string prefix. Example `R'abc'` /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals) - SingleQuotedRawStringLiteral(String), + SingleQuotedRawStringLiteral(QuotedString), /// Double quoted literal with raw string prefix. Example `R"abc"` /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals) - DoubleQuotedRawStringLiteral(String), + DoubleQuotedRawStringLiteral(QuotedString), /// Triple single quoted literal with raw string prefix. Example `R'''abc'''` /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals) TripleSingleQuotedRawStringLiteral(String), @@ -187,7 +187,7 @@ /// [BigQuery](https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#quoted_literals) TripleDoubleQuotedRawStringLiteral(String), /// N'string value' - NationalStringLiteral(String), + NationalStringLiteral(QuotedString), /// Quote delimited literal. Examples `Q'{ab'c}'`, `Q'|ab'c|'`, `Q'|ab|c|'` /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA) QuoteDelimitedStringLiteral(QuoteDelimitedString), @@ -195,10 +195,10 @@ /// [Oracle](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Literals.html#GUID-1824CBAA-6E16-4921-B2A6-112FB02248DA) NationalQuoteDelimitedStringLiteral(QuoteDelimitedString), /// X'hex value' - HexStringLiteral(String), + HexStringLiteral(QuotedString), /// Double quoted string literal, e.g. `"abc"`. - DoubleQuotedString(String), + DoubleQuotedString(QuotedString), /// Boolean value true or false Boolean(bool), /// `NULL` value @@ -220,20 +220,20 @@ match self { Value::SingleQuotedString(s) | Value::DoubleQuotedString(s) - | Value::TripleSingleQuotedString(s) - | Value::TripleDoubleQuotedString(s) | Value::SingleQuotedByteStringLiteral(s) | Value::DoubleQuotedByteStringLiteral(s) - | Value::TripleSingleQuotedByteStringLiteral(s) - | Value::TripleDoubleQuotedByteStringLiteral(s) | Value::SingleQuotedRawStringLiteral(s) | Value::DoubleQuotedRawStringLiteral(s) + | Value::NationalStringLiteral(s) + | Value::HexStringLiteral(s) => Some(s.value.clone()), + Value::TripleSingleQuotedString(s) + | Value::TripleDoubleQuotedString(s) + | Value::TripleSingleQuotedByteStringLiteral(s) + | Value::TripleDoubleQuotedByteStringLiteral(s) | Value::TripleSingleQuotedRawStringLiteral(s) | Value::TripleDoubleQuotedRawStringLiteral(s) | Value::EscapedStringLiteral(s) - | Value::UnicodeStringLiteral(s) - | Value::NationalStringLiteral(s) - | Value::HexStringLiteral(s) => Some(s), + | Value::UnicodeStringLiteral(s) => Some(s), Value::DollarQuotedString(s) => Some(s.value), Value::QuoteDelimitedStringLiteral(s) => Some(s.value), Value::NationalQuoteDelimitedStringLiteral(s) => Some(s.value), @@ -252,6 +252,36 @@ } } +/// Prints a quoted string literal's contents between `quote` delimiters, +/// re-escaping them according to the value's [`QuoteEscaping`] +fn fmt_quoted_string(f: &mut fmt::Formatter, value: &QuotedString, quote: char) -> fmt::Result { + match value.escaping { + QuoteEscaping::Raw => write!(f, "{quote}{value}{quote}", value = value.value), + QuoteEscaping::Double => { + write!(f, "{quote}")?; + let mut parts = value.value.split(quote); + if let Some(part) = parts.next() { + f.write_str(part)?; + } + for part in parts { + write!(f, "{quote}{quote}")?; + f.write_str(part)?; + } + write!(f, "{quote}") + } + QuoteEscaping::Backslash => { + write!(f, "{quote}")?; + for ch in value.value.chars() { + if ch == quote || ch == '\\' { + f.write_str("\\")?; + } + write!(f, "{ch}")?; + } + write!(f, "{quote}") + } + } +} + impl fmt::Display for ValueWithSpan { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.value) @@ -262,8 +292,8 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Value::Number(v, l) => write!(f, "{}{long}", v, long = if *l { "L" } else { "" }), - Value::DoubleQuotedString(v) => write!(f, "\"{}\"", escape_double_quote_string(v)), - Value::SingleQuotedString(v) => write!(f, "'{}'", escape_single_quote_string(v)), + Value::DoubleQuotedString(v) => fmt_quoted_string(f, v, '"'), + Value::SingleQuotedString(v) => fmt_quoted_string(f, v, '\''), Value::TripleSingleQuotedString(v) => { write!(f, "'''{v}'''") } @@ -273,24 +303,34 @@ Value::DollarQuotedString(v) => write!(f, "{v}"), Value::EscapedStringLiteral(v) => write!(f, "E'{}'", escape_escaped_string(v)), Value::UnicodeStringLiteral(v) => write!(f, "U&'{}'", escape_unicode_string(v)), - Value::NationalStringLiteral(v) => write!(f, "N'{}'", escape_single_quote_string(v)), + Value::NationalStringLiteral(v) => { + write!(f, "N")?; + fmt_quoted_string(f, v, '\'') + } Value::QuoteDelimitedStringLiteral(v) => v.fmt(f), Value::NationalQuoteDelimitedStringLiteral(v) => write!(f, "N{v}"), - Value::HexStringLiteral(v) => write!(f, "X'{}'", escape_single_quote_string(v)), + Value::HexStringLiteral(v) => { + write!(f, "X")?; + fmt_quoted_string(f, v, '\'') + } Value::Boolean(v) => write!(f, "{v}"), Value::SingleQuotedByteStringLiteral(v) => { - write!(f, "B'{}'", escape_single_quote_string(v)) + write!(f, "B")?; + fmt_quoted_string(f, v, '\'') } Value::DoubleQuotedByteStringLiteral(v) => { - write!(f, "B\"{}\"", escape_double_quote_string(v)) + write!(f, "B")?; + fmt_quoted_string(f, v, '"') } Value::TripleSingleQuotedByteStringLiteral(v) => write!(f, "B'''{v}'''"), Value::TripleDoubleQuotedByteStringLiteral(v) => write!(f, r#"B"""{v}""""#), Value::SingleQuotedRawStringLiteral(v) => { - write!(f, "R'{}'", escape_single_quote_string(v)) + write!(f, "R")?; + fmt_quoted_string(f, v, '\'') } Value::DoubleQuotedRawStringLiteral(v) => { - write!(f, "R\"{}\"", escape_double_quote_string(v)) + write!(f, "R")?; + fmt_quoted_string(f, v, '"') } Value::TripleSingleQuotedRawStringLiteral(v) => write!(f, "R'''{v}'''"), Value::TripleDoubleQuotedRawStringLiteral(v) => write!(f, r#"R"""{v}""""#), @@ -561,6 +601,107 @@ } } +/// The contents of a quoted string literal and how [`fmt::Display`] +/// re-escapes the contents when the value is printed back between its +/// delimiters. +#[derive(Debug, Clone, Default)] +#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))] +pub struct QuotedString { + /// The literal's contents. + pub value: String, + /// How the contents are stored, which decides how [`fmt::Display`] + /// re-escapes them. + pub escaping: QuoteEscaping, +} + +impl From<String> for QuotedString { + fn from(value: String) -> Self { + Self { + value, + escaping: QuoteEscaping::default(), + } + } +} + +impl From<&str> for QuotedString { + fn from(value: &str) -> Self { + Self { + value: String::from(value), + escaping: QuoteEscaping::default(), + } + } +} + +// `Double` and `Backslash` hold decoded contents and differ only in how +// `fmt::Display` re-escapes them, so they compare as equal +impl PartialEq for QuotedString { + fn eq(&self, other: &Self) -> bool { + self.value == other.value + && (self.escaping == QuoteEscaping::Raw) == (other.escaping == QuoteEscaping::Raw) + } +} + +impl Eq for QuotedString {} + +impl core::hash::Hash for QuotedString { + fn hash<H: core::hash::Hasher>(&self, state: &mut H) { + self.value.hash(state); + (self.escaping == QuoteEscaping::Raw).hash(state); + } +} + +impl PartialOrd for QuotedString { + fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> { + Some(self.cmp(other)) + } +} + +impl Ord for QuotedString { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + let is_raw = self.escaping == QuoteEscaping::Raw; + let other_is_raw = other.escaping == QuoteEscaping::Raw; + self.value + .cmp(&other.value) + .then_with(|| is_raw.cmp(&other_is_raw)) + } +} + +#[cfg(feature = "serde")] +impl Serialize for QuotedString { + fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> { + if self.escaping == QuoteEscaping::Double { + serializer.serialize_str(&self.value) + } else { + let mut state = serializer.serialize_struct("QuotedString", 2)?; + state.serialize_field("value", &self.value)?; + state.serialize_field("escaping", &self.escaping)?; + state.end() + } + } +} + +#[cfg(feature = "serde")] +impl<'de> Deserialize<'de> for QuotedString { + fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> { + #[derive(Deserialize)] + #[serde(untagged)] + enum Wire { + Plain(String), + Struct { + value: String, + escaping: QuoteEscaping, + }, + } + Ok(match Wire::deserialize(deserializer)? { + Wire::Plain(value) => Self { + value, + escaping: QuoteEscaping::default(), + }, + Wire::Struct { value, escaping } => Self { value, escaping }, + }) + } +} + pub struct EscapeQuotedString<'a> { string: &'a str, quote: char, @@ -752,11 +893,11 @@ #[test] fn test_hex_string_literal_display_escaping() { assert_eq!( - Value::HexStringLiteral("'".to_string()).to_string(), + Value::HexStringLiteral("'".to_string().into()).to_string(), "X''''" ); assert_eq!( - Value::HexStringLiteral("it's".to_string()).to_string(), + Value::HexStringLiteral("it's".to_string().into()).to_string(), "X'it''s'" ); } @@ -765,35 +906,35 @@ #[test] fn test_byte_and_raw_string_literal_display_escaping() { assert_eq!( - Value::SingleQuotedByteStringLiteral("'".to_string()).to_string(), + Value::SingleQuotedByteStringLiteral("'".to_string().into()).to_string(), "B''''" ); assert_eq!( - Value::SingleQuotedByteStringLiteral("it's".to_string()).to_string(), + Value::SingleQuotedByteStringLiteral("it's".to_string().into()).to_string(), "B'it''s'" ); assert_eq!( - Value::DoubleQuotedByteStringLiteral("\"".to_string()).to_string(), + Value::DoubleQuotedByteStringLiteral("\"".to_string().into()).to_string(), "B\"\"\"\"" ); assert_eq!( - Value::DoubleQuotedByteStringLiteral("it\"s".to_string()).to_string(), + Value::DoubleQuotedByteStringLiteral("it\"s".to_string().into()).to_string(), "B\"it\"\"s\"" ); assert_eq!( - Value::SingleQuotedRawStringLiteral("'".to_string()).to_string(), + Value::SingleQuotedRawStringLiteral("'".to_string().into()).to_string(), "R''''" ); assert_eq!( - Value::SingleQuotedRawStringLiteral("it's".to_string()).to_string(), + Value::SingleQuotedRawStringLiteral("it's".to_string().into()).to_string(), "R'it''s'" ); assert_eq!( - Value::DoubleQuotedRawStringLiteral("\"".to_string()).to_string(), + Value::DoubleQuotedRawStringLiteral("\"".to_string().into()).to_string(), "R\"\"\"\"" ); assert_eq!( - Value::DoubleQuotedRawStringLiteral("it\"s".to_string()).to_string(), + Value::DoubleQuotedRawStringLiteral("it\"s".to_string().into()).to_string(), "R\"it\"\"s\"" ); }
diff --git a/src/ast/visitor.rs b/src/ast/visitor.rs index c78ff2b..55ec10d 100644 --- a/src/ast/visitor.rs +++ b/src/ast/visitor.rs
@@ -1309,7 +1309,7 @@ fn pre_visit_value(&mut self, value: &mut ValueWithSpan) -> ControlFlow<Self::Break> { self.index += 1; - value.value = Value::SingleQuotedString(format!("REDACTED_{}", self.index)); + value.value = Value::SingleQuotedString(format!("REDACTED_{}", self.index).into()); ControlFlow::Continue(()) }
diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 9adf6e6..f4a55d4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs
@@ -13004,8 +13004,12 @@ } Keyword::NULL => ok_value(Value::Null), Keyword::NoKeyword if w.quote_style.is_some() => match w.quote_style { - Some('"') => ok_value(Value::DoubleQuotedString(w.value)), - Some('\'') => ok_value(Value::SingleQuotedString(w.value)), + Some('"') => ok_value(Value::DoubleQuotedString( + self.quoted_string(w.value, false), + )), + Some('\'') => ok_value(Value::SingleQuotedString( + self.quoted_string(w.value, false), + )), _ => self.expected( "A value?", TokenWithSpan { @@ -13026,12 +13030,20 @@ Token::Number(n, l) => { ok_value(Value::Number(Self::parse_number_literal(n, span.start)?, l)) } - Token::SingleQuotedString(ref s) => ok_value(Value::SingleQuotedString( - self.maybe_concat_string_literal(s.to_string()), - )), - Token::DoubleQuotedString(ref s) => ok_value(Value::DoubleQuotedString( - self.maybe_concat_string_literal(s.to_string()), - )), + Token::SingleQuotedString(ref s) => { + let literal = self.maybe_concat_string_literal(s.to_string()); + ok_value(Value::SingleQuotedString(self.quoted_string( + literal, + self.dialect.supports_string_literal_backslash_escape(), + ))) + } + Token::DoubleQuotedString(ref s) => { + let literal = self.maybe_concat_string_literal(s.to_string()); + ok_value(Value::DoubleQuotedString(self.quoted_string( + literal, + self.dialect.supports_string_literal_backslash_escape(), + ))) + } Token::TripleSingleQuotedString(ref s) => { ok_value(Value::TripleSingleQuotedString(s.to_string())) } @@ -13039,24 +13051,24 @@ ok_value(Value::TripleDoubleQuotedString(s.to_string())) } Token::DollarQuotedString(ref s) => ok_value(Value::DollarQuotedString(s.clone())), - Token::SingleQuotedByteStringLiteral(ref s) => { - ok_value(Value::SingleQuotedByteStringLiteral(s.clone())) - } - Token::DoubleQuotedByteStringLiteral(ref s) => { - ok_value(Value::DoubleQuotedByteStringLiteral(s.clone())) - } + Token::SingleQuotedByteStringLiteral(ref s) => ok_value( + Value::SingleQuotedByteStringLiteral(self.quoted_string(s.clone(), false)), + ), + Token::DoubleQuotedByteStringLiteral(ref s) => ok_value( + Value::DoubleQuotedByteStringLiteral(self.quoted_string(s.clone(), false)), + ), Token::TripleSingleQuotedByteStringLiteral(ref s) => { ok_value(Value::TripleSingleQuotedByteStringLiteral(s.clone())) } Token::TripleDoubleQuotedByteStringLiteral(ref s) => { ok_value(Value::TripleDoubleQuotedByteStringLiteral(s.clone())) } - Token::SingleQuotedRawStringLiteral(ref s) => { - ok_value(Value::SingleQuotedRawStringLiteral(s.clone())) - } - Token::DoubleQuotedRawStringLiteral(ref s) => { - ok_value(Value::DoubleQuotedRawStringLiteral(s.clone())) - } + Token::SingleQuotedRawStringLiteral(ref s) => ok_value( + Value::SingleQuotedRawStringLiteral(self.quoted_string(s.clone(), false)), + ), + Token::DoubleQuotedRawStringLiteral(ref s) => ok_value( + Value::DoubleQuotedRawStringLiteral(self.quoted_string(s.clone(), false)), + ), Token::TripleSingleQuotedRawStringLiteral(ref s) => { ok_value(Value::TripleSingleQuotedRawStringLiteral(s.clone())) } @@ -13064,7 +13076,10 @@ ok_value(Value::TripleDoubleQuotedRawStringLiteral(s.clone())) } Token::NationalStringLiteral(ref s) => { - ok_value(Value::NationalStringLiteral(s.to_string())) + ok_value(Value::NationalStringLiteral(self.quoted_string( + s.to_string(), + self.dialect.supports_string_literal_backslash_escape(), + ))) } Token::QuoteDelimitedStringLiteral(v) => { ok_value(Value::QuoteDelimitedStringLiteral(v)) @@ -13078,7 +13093,9 @@ Token::UnicodeStringLiteral(ref s) => { ok_value(Value::UnicodeStringLiteral(s.to_string())) } - Token::HexStringLiteral(ref s) => ok_value(Value::HexStringLiteral(s.to_string())), + Token::HexStringLiteral(ref s) => ok_value(Value::HexStringLiteral( + self.quoted_string(s.to_string(), false), + )), Token::Placeholder(ref s) => ok_value(Value::Placeholder(s.to_string())), tok @ Token::Colon | tok @ Token::AtSign => { // 1. Not calling self.parse_identifier(false)? @@ -13186,13 +13203,21 @@ let span = next_token.span; match next_token.token { Token::SingleQuotedString(ref s) => Ok(Expr::Value( - Value::SingleQuotedString(s.to_string()).with_span(span), + Value::SingleQuotedString(self.quoted_string( + s.to_string(), + self.dialect.supports_string_literal_backslash_escape(), + )) + .with_span(span), )), Token::DoubleQuotedString(ref s) => Ok(Expr::Value( - Value::DoubleQuotedString(s.to_string()).with_span(span), + Value::DoubleQuotedString(self.quoted_string( + s.to_string(), + self.dialect.supports_string_literal_backslash_escape(), + )) + .with_span(span), )), Token::HexStringLiteral(ref s) => Ok(Expr::Value( - Value::HexStringLiteral(s.to_string()).with_span(span), + Value::HexStringLiteral(self.quoted_string(s.to_string(), false)).with_span(span), )), unexpected => self.expected( "a string value", @@ -13225,9 +13250,13 @@ parser.next_token(); Ok(Expr::Value(Value::DollarQuotedString(s).with_span(span))) } - _ => Ok(Expr::Value( - Value::SingleQuotedString(parser.parse_literal_string()?).with_span(span), - )), + _ => { + let body = parser.parse_literal_string()?; + Ok(Expr::Value( + Value::SingleQuotedString(parser.quoted_string(body, false)) + .with_span(span), + )) + } } }; @@ -14552,6 +14581,28 @@ } } + /// The [`QuoteEscaping`] marker for string values parsed from this + /// parser's tokens. `backslash_escape` mirrors the tokenizer's decode + /// policy for the literal's kind + pub(crate) fn string_escaping(&self, backslash_escape: bool) -> QuoteEscaping { + if !self.options.unescape { + QuoteEscaping::Raw + } else if backslash_escape { + QuoteEscaping::Backslash + } else { + QuoteEscaping::Double + } + } + + /// Wrap parsed string literal contents in a [`QuotedString`] stamped + /// with this parser's [`QuoteEscaping`] marker + pub(crate) fn quoted_string(&self, value: String, backslash_escape: bool) -> QuotedString { + QuotedString { + value, + escaping: self.string_escaping(backslash_escape), + } + } + /// Convert a word token into an [`Ident`] stamped with this parser's /// [`QuoteEscaping`] marker pub(crate) fn word_ident(&self, w: Word, span: Span) -> Ident {
diff --git a/src/test_utils.rs b/src/test_utils.rs index aba2836..32a6ff9 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs
@@ -367,7 +367,7 @@ /// Creates a [Value::SingleQuotedString] pub fn single_quoted_string(s: impl Into<String>) -> Value { - Value::SingleQuotedString(s.into()) + Value::SingleQuotedString(QuotedString::from(s.into())) } pub fn table_alias(explicit: bool, name: impl Into<String>) -> Option<TableAlias> {
diff --git a/tests/sqlparser_bigquery.rs b/tests/sqlparser_bigquery.rs index 41e7aca..498bc42 100644 --- a/tests/sqlparser_bigquery.rs +++ b/tests/sqlparser_bigquery.rs
@@ -52,11 +52,23 @@ let select = dialect.verified_only_select(sql); assert_eq!(12, select.projection.len()); assert_eq!( - &Expr::Value(Value::SingleQuotedString("single".into()).with_empty_span()), + &Expr::Value( + Value::SingleQuotedString(QuotedString { + value: "single".into(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() + ), expr_from_projection(&select.projection[0]) ); assert_eq!( - &Expr::Value(Value::DoubleQuotedString("double".into()).with_empty_span()), + &Expr::Value( + Value::DoubleQuotedString(QuotedString { + value: "double".into(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() + ), expr_from_projection(&select.projection[1]) ); assert_eq!( @@ -68,7 +80,13 @@ expr_from_projection(&select.projection[3]) ); assert_eq!( - &Expr::Value(Value::SingleQuotedString(r#"single\'escaped"#.into()).with_empty_span()), + &Expr::Value( + Value::SingleQuotedString(QuotedString { + value: r#"single\'escaped"#.into(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() + ), expr_from_projection(&select.projection[4]) ); assert_eq!( @@ -84,7 +102,13 @@ expr_from_projection(&select.projection[6]) ); assert_eq!( - &Expr::Value(Value::DoubleQuotedString(r#"double\"escaped"#.to_string()).with_empty_span()), + &Expr::Value( + Value::DoubleQuotedString(QuotedString { + value: r#"double\"escaped"#.into(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() + ), expr_from_projection(&select.projection[7]) ); assert_eq!( @@ -134,26 +158,28 @@ assert_eq!(6, select.projection.len()); assert_eq!( &Expr::Value( - Value::SingleQuotedByteStringLiteral("abc".to_string()).with_empty_span() + Value::SingleQuotedByteStringLiteral("abc".to_string().into()) + .with_empty_span() ), expr_from_projection(&select.projection[0]) ); assert_eq!( &Expr::Value( - Value::DoubleQuotedByteStringLiteral("abc".to_string()).with_empty_span() + Value::DoubleQuotedByteStringLiteral("abc".to_string().into()) + .with_empty_span() ), expr_from_projection(&select.projection[1]) ); assert_eq!( &Expr::Value( - Value::SingleQuotedByteStringLiteral(r"f\(abc,(.*),def\)".to_string()) + Value::SingleQuotedByteStringLiteral(r"f\(abc,(.*),def\)".to_string().into()) .with_empty_span() ), expr_from_projection(&select.projection[2]) ); assert_eq!( &Expr::Value( - Value::DoubleQuotedByteStringLiteral(r"f\(abc,(.*),def\)".to_string()) + Value::DoubleQuotedByteStringLiteral(r"f\(abc,(.*),def\)".to_string().into()) .with_empty_span() ), expr_from_projection(&select.projection[3]) @@ -200,26 +226,26 @@ assert_eq!(6, select.projection.len()); assert_eq!( &Expr::Value( - Value::SingleQuotedRawStringLiteral("abc".to_string()).with_empty_span() + Value::SingleQuotedRawStringLiteral("abc".to_string().into()).with_empty_span() ), expr_from_projection(&select.projection[0]) ); assert_eq!( &Expr::Value( - Value::DoubleQuotedRawStringLiteral("abc".to_string()).with_empty_span() + Value::DoubleQuotedRawStringLiteral("abc".to_string().into()).with_empty_span() ), expr_from_projection(&select.projection[1]) ); assert_eq!( &Expr::Value( - Value::SingleQuotedRawStringLiteral(r"f\(abc,(.*),def\)".to_string()) + Value::SingleQuotedRawStringLiteral(r"f\(abc,(.*),def\)".to_string().into()) .with_empty_span() ), expr_from_projection(&select.projection[2]) ); assert_eq!( &Expr::Value( - Value::DoubleQuotedRawStringLiteral(r"f\(abc,(.*),def\)".to_string()) + Value::DoubleQuotedRawStringLiteral(r"f\(abc,(.*),def\)".to_string().into()) .with_empty_span() ), expr_from_projection(&select.projection[3]) @@ -361,9 +387,11 @@ vec![SqlOption::KeyValue { key: Ident::new("description"), value: Expr::Value( - Value::DoubleQuotedString("field age".to_string()).with_span( - Span::new(Location::new(1, 42), Location::new(1, 52)) - ) + Value::DoubleQuotedString("field age".to_string().into()) + .with_span(Span::new( + Location::new(1, 42), + Location::new(1, 52) + )) ), }] )])), @@ -386,8 +414,10 @@ &SqlOption::KeyValue { key: Ident::new("description"), value: Expr::Value( - Value::DoubleQuotedString("a view that expires in 2 days".to_string()) - .with_empty_span() + Value::DoubleQuotedString( + "a view that expires in 2 days".to_string().into() + ) + .with_empty_span() ), }, &options[2], @@ -513,9 +543,11 @@ option: ColumnOption::Options(vec![SqlOption::KeyValue { key: Ident::new("description"), value: Expr::Value( - Value::DoubleQuotedString("field x".to_string()).with_span( - Span::new(Location::new(1, 42), Location::new(1, 52)) - ) + Value::DoubleQuotedString("field x".to_string().into()) + .with_span(Span::new( + Location::new(1, 42), + Location::new(1, 52) + )) ), },]) }, @@ -529,9 +561,11 @@ option: ColumnOption::Options(vec![SqlOption::KeyValue { key: Ident::new("description"), value: Expr::Value( - Value::DoubleQuotedString("field y".to_string()).with_span( - Span::new(Location::new(1, 42), Location::new(1, 52)) - ) + Value::DoubleQuotedString("field y".to_string().into()) + .with_span(Span::new( + Location::new(1, 42), + Location::new(1, 52) + )) ), },]) }] @@ -559,11 +593,10 @@ SqlOption::KeyValue { key: Ident::new("description"), value: Expr::Value( - Value::DoubleQuotedString("table option description".to_string()) - .with_span(Span::new( - Location::new(1, 42), - Location::new(1, 52) - )) + Value::DoubleQuotedString( + "table option description".to_string().into() + ) + .with_span(Span::new(Location::new(1, 42), Location::new(1, 52))) ), }, ]) @@ -1772,7 +1805,7 @@ args: None, with_hints: vec![], version: Some(TableVersion::ForSystemTimeAsOf(Expr::Value( - Value::SingleQuotedString(version.clone()).with_empty_span() + Value::SingleQuotedString(version.clone().into()).with_empty_span() ))), partitions: vec![], with_ordinality: false, @@ -2476,12 +2509,12 @@ assert_eq!( &Expr::Trim { expr: Box::new(Expr::Value( - Value::SingleQuotedString("xyz".to_owned()).with_empty_span() + Value::SingleQuotedString("xyz".to_owned().into()).with_empty_span() )), trim_where: None, trim_what: None, trim_characters: Some(vec![Expr::Value( - Value::SingleQuotedString("a".to_owned()).with_empty_span() + Value::SingleQuotedString("a".to_owned().into()).with_empty_span() )]), }, expr_from_projection(only(&select.projection)) @@ -2723,14 +2756,14 @@ SqlOption::KeyValue { key: Ident::new("uri"), value: Expr::Value( - Value::SingleQuotedString("gs://bucket/folder/*".to_owned()) + Value::SingleQuotedString("gs://bucket/folder/*".to_owned().into()) .with_empty_span() ), }, SqlOption::KeyValue { key: Ident::new("format"), value: Expr::Value( - Value::SingleQuotedString("PARQUET".to_owned()).with_empty_span() + Value::SingleQuotedString("PARQUET".to_owned().into()).with_empty_span() ), }, SqlOption::KeyValue { @@ -2825,14 +2858,14 @@ SqlOption::KeyValue { key: Ident::new("uri"), value: Expr::Value( - Value::SingleQuotedString("gs://bucket/folder/*".to_owned()) + Value::SingleQuotedString("gs://bucket/folder/*".to_owned().into()) .with_empty_span() ), }, SqlOption::KeyValue { key: Ident::new("format"), value: Expr::Value( - Value::SingleQuotedString("PARQUET".to_owned()).with_empty_span() + Value::SingleQuotedString("PARQUET".to_owned().into()).with_empty_span() ), }, SqlOption::KeyValue { @@ -3015,3 +3048,15 @@ err ); } + +#[test] +fn decoded_string_values_re_escape_quotes_with_backslash() { + // A decoded value that contains a quote is printed with `\'`, because + // BigQuery single-quoted strings reject a doubled quote + // https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#lexical_structure + bigquery().one_statement_parses_to(r#"SELECT 'a''b'"#, r"SELECT 'a\'b'"); + bigquery().verified_stmt(r"SELECT 'a\'b'"); + bigquery().verified_stmt(r"SELECT 'a\\b'"); + bigquery().one_statement_parses_to(r#"SELECT "a""b""#, r#"SELECT "a\"b""#); + bigquery().verified_stmt(r#"SELECT "a\"b""#); +}
diff --git a/tests/sqlparser_clickhouse.rs b/tests/sqlparser_clickhouse.rs index a6ce583..8b199f6 100644 --- a/tests/sqlparser_clickhouse.rs +++ b/tests/sqlparser_clickhouse.rs
@@ -58,7 +58,7 @@ "indexOf", [ Expr::Identifier(Ident::new("string_names")), - Expr::value(Value::SingleQuotedString("endpoint".to_string())) + Expr::value(Value::SingleQuotedString("endpoint".to_string().into())) ] ), })], @@ -75,7 +75,9 @@ left: Box::new(BinaryOp { left: Box::new(Identifier(Ident::new("id"))), op: BinaryOperator::Eq, - right: Box::new(Expr::value(Value::SingleQuotedString("test".to_string()))), + right: Box::new(Expr::value(Value::SingleQuotedString( + "test".to_string().into() + ))), }), op: BinaryOperator::And, right: Box::new(BinaryOp { @@ -86,13 +88,17 @@ "indexOf", [ Expr::Identifier(Ident::new("string_name")), - Expr::value(Value::SingleQuotedString("app".to_string())) + Expr::value(Value::SingleQuotedString( + "app".to_string().into() + )) ] ), })], }), op: BinaryOperator::NotEq, - right: Box::new(Expr::value(Value::SingleQuotedString("foo".to_string()))), + right: Box::new(Expr::value(Value::SingleQuotedString( + "foo".to_string().into() + ))), }), }), group_by: GroupByExpr::Expressions(vec![], vec![]), @@ -118,8 +124,8 @@ assert_eq!( &Expr::Array(Array { elem: vec![ - Expr::value(Value::SingleQuotedString("1".to_string())), - Expr::value(Value::SingleQuotedString("2".to_string())), + Expr::value(Value::SingleQuotedString("1".to_string().into())), + Expr::value(Value::SingleQuotedString("2".to_string().into())), ], named: false, }), @@ -1537,7 +1543,7 @@ let sql = format!("ALTER TABLE t {operation_name} PARTITION '2024-08-14'"); let expected_partition = Partition::Expr(Expr::Value( - Value::SingleQuotedString("2024-08-14".to_string()).with_empty_span(), + Value::SingleQuotedString("2024-08-14".to_string().into()).with_empty_span(), )); match clickhouse_and_generic().verified_stmt(&sql) { Statement::AlterTable(AlterTable { operations, .. }) => { @@ -1567,7 +1573,7 @@ Statement::AlterTable(AlterTable { operations, .. }) => { assert_eq!(operations.len(), 1); let expected_partition = Partition::Expr(Expr::Value( - Value::SingleQuotedString("2024-08-14".to_string()).with_empty_span(), + Value::SingleQuotedString("2024-08-14".to_string().into()).with_empty_span(), )); let expected_operation = if operation_name == &"FREEZE" { AlterTableOperation::FreezePartition {
diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 718e4d4..be22c56 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs
@@ -656,7 +656,8 @@ Ident::new("username") ])), value: Expr::Value( - (Value::SingleQuotedString("new_user".to_string())).with_empty_span() + (Value::SingleQuotedString("new_user".to_string().into())) + .with_empty_span() ), }], assignments @@ -669,7 +670,8 @@ ])), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("old_user".to_string())).with_empty_span() + (Value::SingleQuotedString("old_user".to_string().into())) + .with_empty_span() )), }), selection @@ -1628,7 +1630,7 @@ left: Box::new(Expr::Identifier(Ident::new("salary"))), op: NotEq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("Jim's salary".to_string())).with_empty_span() + (Value::SingleQuotedString("Jim's salary".to_string().into())).with_empty_span() )), }), ast.selection, @@ -1654,7 +1656,11 @@ left: Box::new(Expr::Identifier(Ident::new("salary"))), op: NotEq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("Jim''s salary".to_string())).with_empty_span() + (Value::SingleQuotedString(QuotedString { + value: "Jim''s salary".to_string(), + escaping: QuoteEscaping::Raw, + })) + .with_empty_span() )), }), ast.selection, @@ -2379,7 +2385,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: None, any: false, @@ -2398,10 +2404,10 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: Some(Box::new(Expr::value( - Value::SingleQuotedString('^'.to_string()).with_empty_span(), + Value::SingleQuotedString('^'.to_string().into()).with_empty_span(), ))), any: false, }, @@ -2420,7 +2426,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: None, any: false, @@ -2476,7 +2482,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: None, any: false, @@ -2495,10 +2501,10 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: Some(Box::new(Expr::value( - Value::SingleQuotedString('^'.to_string()).with_empty_span(), + Value::SingleQuotedString('^'.to_string().into()).with_empty_span(), ))), any: false, }, @@ -2517,7 +2523,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: None, any: false, @@ -2547,7 +2553,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: None, }, @@ -2565,10 +2571,10 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: Some(Box::new(Expr::value( - Value::SingleQuotedString('^'.to_string()).with_empty_span(), + Value::SingleQuotedString('^'.to_string().into()).with_empty_span(), ))), }, select.selection.unwrap() @@ -2584,7 +2590,7 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: Some(Box::new(Expr::value(Value::Null.with_empty_span()))), }, @@ -2602,10 +2608,10 @@ expr: Box::new(Expr::Identifier(Ident::new("name"))), negated, pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("%a".to_string())).with_empty_span() + (Value::SingleQuotedString("%a".to_string().into())).with_empty_span() )), escape_char: Some(Box::new(Expr::value( - Value::SingleQuotedString('^'.to_string()).with_empty_span(), + Value::SingleQuotedString('^'.to_string().into()).with_empty_span(), ))), })), select.selection.unwrap() @@ -2627,8 +2633,12 @@ Expr::In { expr: Box::new(Expr::Identifier(Ident::new("segment"))), target: InTarget::List(vec![ - Expr::Value((Value::SingleQuotedString("HIGH".to_string())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("MED".to_string())).with_empty_span()), + Expr::Value( + (Value::SingleQuotedString("HIGH".to_string().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("MED".to_string().into())).with_empty_span() + ), ]), negated, global: false, @@ -4034,13 +4044,13 @@ "dateid" )))), FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString(", ".to_owned())).with_empty_span() + (Value::SingleQuotedString(", ".to_owned().into())).with_empty_span() ))) ], clauses: vec![FunctionArgumentClause::OnOverflow( ListAggOnOverflow::Truncate { filler: Some(Box::new(Expr::Value( - (Value::SingleQuotedString("%".to_string(),)).with_empty_span() + (Value::SingleQuotedString("%".to_string().into(),)).with_empty_span() ))), with_count: false, } @@ -5031,7 +5041,7 @@ value: Value::SingleQuotedString(s), span: _, })), - } => assert_eq!(s, "No rows in my_table"), + } => assert_eq!(s.value, "No rows in my_table"), _ => unreachable!(), } } @@ -5522,7 +5532,7 @@ span: Span::empty(), }, value: Expr::Value( - (Value::SingleQuotedString("parquet".to_string())).with_empty_span() + (Value::SingleQuotedString("parquet".to_string().into())).with_empty_span() ), }], ); @@ -6395,14 +6405,14 @@ FunctionArg::Named { name: Ident::new("a"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("1".to_owned())).with_empty_span() + (Value::SingleQuotedString("1".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::RightArrow }, FunctionArg::Named { name: Ident::new("b"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("2".to_owned())).with_empty_span() + (Value::SingleQuotedString("2".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::RightArrow }, @@ -6435,14 +6445,14 @@ FunctionArg::Named { name: Ident::new("a"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("1".to_owned())).with_empty_span() + (Value::SingleQuotedString("1".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::Equals }, FunctionArg::Named { name: Ident::new("b"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("2".to_owned())).with_empty_span() + (Value::SingleQuotedString("2".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::Equals }, @@ -6916,17 +6926,17 @@ let select = national_string_dialects.verified_only_select(sql); assert_eq!(3, select.projection.len()); assert_eq!( - &Expr::Value((Value::SingleQuotedString("one".to_string())).with_empty_span()), + &Expr::Value((Value::SingleQuotedString("one".to_string().into())).with_empty_span()), expr_from_projection(&select.projection[0]) ); assert_eq!( &Expr::Value( - (Value::NationalStringLiteral("national string".to_string())).with_empty_span() + (Value::NationalStringLiteral("national string".to_string().into())).with_empty_span() ), expr_from_projection(&select.projection[1]) ); assert_eq!( - &Expr::Value((Value::HexStringLiteral("deadBEEF".to_string())).with_empty_span()), + &Expr::Value((Value::HexStringLiteral("deadBEEF".to_string().into())).with_empty_span()), expr_from_projection(&select.projection[2]) ); @@ -7037,7 +7047,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1-1"))).with_empty_span() + (Value::SingleQuotedString(String::from("1-1").into())).with_empty_span() )), leading_field: Some(DateTimeField::Year), leading_precision: None, @@ -7052,7 +7062,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("01:01.01"))).with_empty_span() + (Value::SingleQuotedString(String::from("01:01.01").into())).with_empty_span() )), leading_field: Some(DateTimeField::Minute), leading_precision: Some(5), @@ -7067,7 +7077,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1"))).with_empty_span() + (Value::SingleQuotedString(String::from("1").into())).with_empty_span() )), leading_field: Some(DateTimeField::Second), leading_precision: Some(5), @@ -7082,7 +7092,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("10"))).with_empty_span() + (Value::SingleQuotedString(String::from("10").into())).with_empty_span() )), leading_field: Some(DateTimeField::Hour), leading_precision: None, @@ -7126,7 +7136,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("10"))).with_empty_span() + (Value::SingleQuotedString(String::from("10").into())).with_empty_span() )), leading_field: Some(DateTimeField::Hour), leading_precision: Some(1), @@ -7197,7 +7207,7 @@ assert_eq!( &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1 DAY"))).with_empty_span() + (Value::SingleQuotedString(String::from("1 DAY").into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7253,11 +7263,11 @@ &Expr::Interval(Interval { value: Box::new(Expr::BinaryOp { left: Box::new(Expr::Value( - (Value::SingleQuotedString("1".to_string())).with_empty_span() + (Value::SingleQuotedString("1".to_string().into())).with_empty_span() )), op: BinaryOperator::Plus, right: Box::new(Expr::Value( - (Value::SingleQuotedString("1".to_string())).with_empty_span() + (Value::SingleQuotedString("1".to_string().into())).with_empty_span() )), }), leading_field: Some(DateTimeField::Day), @@ -7275,16 +7285,16 @@ value: Box::new(Expr::BinaryOp { left: Box::new(Expr::BinaryOp { left: Box::new(Expr::Value( - (Value::SingleQuotedString("1".to_string())).with_empty_span() + (Value::SingleQuotedString("1".to_string().into())).with_empty_span() )), op: BinaryOperator::Plus, right: Box::new(Expr::Value( - (Value::SingleQuotedString("2".to_string())).with_empty_span() + (Value::SingleQuotedString("2".to_string().into())).with_empty_span() )), }), op: BinaryOperator::Minus, right: Box::new(Expr::Value( - (Value::SingleQuotedString("3".to_string())).with_empty_span() + (Value::SingleQuotedString("3".to_string().into())).with_empty_span() )), }), leading_field: Some(DateTimeField::Day), @@ -7305,7 +7315,7 @@ expr_from_projection(only(&select.projection)), &Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1 DAY"))).with_empty_span() + (Value::SingleQuotedString(String::from("1 DAY").into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7328,7 +7338,7 @@ &Expr::BinaryOp { left: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1 DAY"))).with_empty_span() + (Value::SingleQuotedString(String::from("1 DAY").into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7338,7 +7348,7 @@ op: BinaryOperator::Gt, right: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString(String::from("1 SECOND"))).with_empty_span() + (Value::SingleQuotedString(String::from("1 SECOND").into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7358,7 +7368,7 @@ Expr::BinaryOp { left: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString("1 second".to_string())).with_empty_span() + (Value::SingleQuotedString("1 second".to_string().into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7386,7 +7396,7 @@ kind: CastKind::DoubleColon, expr: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString("1 second".to_string())).with_empty_span() + (Value::SingleQuotedString("1 second".to_string().into())).with_empty_span() )), leading_field: None, leading_precision: None, @@ -7504,7 +7514,8 @@ op: BinaryOperator::Plus, right: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString("5 days".to_string())).with_empty_span(), + (Value::SingleQuotedString("5 days".to_string().into())) + .with_empty_span(), )), leading_field: None, leading_precision: None, @@ -7532,7 +7543,8 @@ op: BinaryOperator::Plus, right: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - (Value::SingleQuotedString("3 days".to_string())).with_empty_span(), + (Value::SingleQuotedString("3 days".to_string().into())) + .with_empty_span(), )), leading_field: None, leading_precision: None, @@ -7594,7 +7606,7 @@ &Expr::AtTimeZone { timestamp: Box::new(call("FROM_UNIXTIME", [zero.clone()])), time_zone: Box::new(Expr::Value( - (Value::SingleQuotedString("UTC-06:00".to_string())).with_empty_span() + (Value::SingleQuotedString("UTC-06:00".to_string().into())).with_empty_span() )), }, expr_from_projection(only(&select.projection)), @@ -7610,11 +7622,13 @@ Expr::AtTimeZone { timestamp: Box::new(call("FROM_UNIXTIME", [zero])), time_zone: Box::new(Expr::Value( - (Value::SingleQuotedString("UTC-06:00".to_string())).with_empty_span() + (Value::SingleQuotedString("UTC-06:00".to_string().into())) + .with_empty_span() )), }, Expr::Value( - (Value::SingleQuotedString("%Y-%m-%dT%H".to_string())).with_empty_span() + (Value::SingleQuotedString("%Y-%m-%dT%H".to_string().into())) + .with_empty_span() ) ] ), @@ -7678,6 +7692,7 @@ } }"# .to_string() + .into() ), span: Span::empty(), }, @@ -7828,7 +7843,7 @@ call( "FUN", [Expr::Value( - (Value::SingleQuotedString("1".to_owned())).with_empty_span() + (Value::SingleQuotedString("1".to_owned().into())).with_empty_span() )], ), expr @@ -8088,7 +8103,7 @@ conditions: vec![ CaseWhen { condition: IsNull(Box::new(Identifier(Ident::new("bar")))), - result: Expr::value(Value::SingleQuotedString("null".to_string())), + result: Expr::value(Value::SingleQuotedString("null".to_string().into())), }, CaseWhen { condition: BinaryOp { @@ -8096,7 +8111,7 @@ op: Eq, right: Box::new(Expr::value(number("0"))), }, - result: Expr::value(Value::SingleQuotedString("=0".to_string())), + result: Expr::value(Value::SingleQuotedString("=0".to_string().into())), }, CaseWhen { condition: BinaryOp { @@ -8104,11 +8119,11 @@ op: GtEq, right: Box::new(Expr::value(number("0"))), }, - result: Expr::value(Value::SingleQuotedString(">=0".to_string())), + result: Expr::value(Value::SingleQuotedString(">=0".to_string().into())), }, ], else_result: Some(Box::new(Expr::value(Value::SingleQuotedString( - "<0".to_string() + "<0".to_string().into() )))), }, expr_from_projection(only(&select.projection)), @@ -8128,10 +8143,10 @@ operand: Some(Box::new(Identifier(Ident::new("foo")))), conditions: vec![CaseWhen { condition: Expr::value(number("1")), - result: Expr::value(Value::SingleQuotedString("Y".to_string())), + result: Expr::value(Value::SingleQuotedString("Y".to_string().into())), }], else_result: Some(Box::new(Expr::value(Value::SingleQuotedString( - "N".to_string() + "N".to_string().into() )))), }, expr_from_projection(only(&select.projection)), @@ -8968,7 +8983,7 @@ assert_eq!( &Expr::Overlay { expr: Box::new(Expr::Value( - (Value::SingleQuotedString("abcdef".to_string())).with_empty_span() + (Value::SingleQuotedString("abcdef".to_string().into())).with_empty_span() )), overlay_what: Box::new(Expr::Identifier(Ident::new("name"))), overlay_from: Box::new(Expr::value(number("3"))), @@ -9024,12 +9039,12 @@ assert_eq!( &Expr::Trim { expr: Box::new(Expr::Value( - Value::SingleQuotedString(" xyz ".to_owned()).with_empty_span() + Value::SingleQuotedString(" xyz ".to_owned().into()).with_empty_span() )), trim_where: None, trim_what: None, trim_characters: Some(vec![Expr::Value( - Value::SingleQuotedString(" ".to_owned()).with_empty_span() + Value::SingleQuotedString(" ".to_owned().into()).with_empty_span() )]), }, expr_from_projection(only(&select.projection)) @@ -9040,12 +9055,12 @@ assert_eq!( &Expr::Trim { expr: Box::new(Expr::Value( - Value::SingleQuotedString("xyz".to_owned()).with_empty_span() + Value::SingleQuotedString("xyz".to_owned().into()).with_empty_span() )), trim_where: None, trim_what: None, trim_characters: Some(vec![Expr::Value( - Value::SingleQuotedString("a".to_owned()).with_empty_span() + Value::SingleQuotedString("a".to_owned().into()).with_empty_span() )]), }, expr_from_projection(only(&select.projection)) @@ -10243,14 +10258,14 @@ timestamp: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2001-01-01T00:00:00.000Z".to_string())) + (Value::SingleQuotedString("2001-01-01T00:00:00.000Z".to_string().into())) .with_empty_span() )), data_type: DataType::Timestamp(None, TimezoneInfo::None), format: None }), time_zone: Box::new(Expr::Value( - (Value::SingleQuotedString("Europe/Brussels".to_string())).with_empty_span() + (Value::SingleQuotedString("Europe/Brussels".to_string().into())).with_empty_span() )), }, expr_from_projection(only(&select.projection)), @@ -11156,7 +11171,8 @@ ])), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("a".to_string())).with_empty_span() + (Value::SingleQuotedString("a".to_string().into())) + .with_empty_span() )), }), action: MergeAction::Update(MergeUpdateExpr { @@ -11726,7 +11742,7 @@ assert_eq!( Expr::Position { expr: Box::new(Expr::Value( - (Value::SingleQuotedString("@".to_string())).with_empty_span() + (Value::SingleQuotedString("@".to_string().into())).with_empty_span() )), r#in: Box::new(Expr::Identifier(Ident::new("field"))), }, @@ -11738,8 +11754,10 @@ call( "position", [ - Expr::Value((Value::SingleQuotedString("an".to_owned())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("banana".to_owned())).with_empty_span()), + Expr::Value((Value::SingleQuotedString("an".to_owned().into())).with_empty_span()), + Expr::Value( + (Value::SingleQuotedString("banana".to_owned().into())).with_empty_span() + ), Expr::value(number("1")), ] ), @@ -12381,7 +12399,8 @@ assert_eq!( *expr, Expr::Value( - (Value::SingleQuotedString(quoted.to_string())).with_empty_span() + (Value::SingleQuotedString(quoted.to_string().into())) + .with_empty_span() ) ); } @@ -12444,7 +12463,11 @@ assert_eq!( *expr, Expr::Value( - (Value::SingleQuotedString(quoted.to_string())).with_empty_span() + (Value::SingleQuotedString(QuotedString { + value: quoted.to_string(), + escaping: QuoteEscaping::Raw, + })) + .with_empty_span() ) ); } @@ -12522,7 +12545,7 @@ }, ExprWithAlias { expr: Expr::Value( - (Value::SingleQuotedString("two".to_string())).with_empty_span() + (Value::SingleQuotedString("two".to_string().into())).with_empty_span() ), alias: None }, @@ -12606,7 +12629,8 @@ ExprWithAlias { expr: Expr::Tuple(vec![ Expr::Value( - (Value::SingleQuotedString("John".to_string())).with_empty_span() + (Value::SingleQuotedString("John".to_string().into())) + .with_empty_span() ), Expr::Value( (Value::Number("30".parse().unwrap(), false)).with_empty_span() @@ -12617,7 +12641,8 @@ ExprWithAlias { expr: Expr::Tuple(vec![ Expr::Value( - (Value::SingleQuotedString("Mike".to_string())).with_empty_span() + (Value::SingleQuotedString("Mike".to_string().into())) + .with_empty_span() ), Expr::Value( (Value::Number("40".parse().unwrap(), false)).with_empty_span() @@ -12985,14 +13010,14 @@ value_source: PivotValueSource::List(vec![ ExprWithAlias { expr: Expr::Value( - (Value::SingleQuotedString("population_2000".to_string())) + (Value::SingleQuotedString("population_2000".to_string().into())) .with_empty_span() ), alias: None }, ExprWithAlias { expr: Expr::Value( - (Value::SingleQuotedString("population_2010".to_string())) + (Value::SingleQuotedString("population_2010".to_string().into())) .with_empty_span() ), alias: None @@ -13465,7 +13490,7 @@ args: FunctionArguments::List(FunctionArgumentList { duplicate_treatment: None, args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("a".to_string())).with_empty_span() + (Value::SingleQuotedString("a".to_string().into())).with_empty_span() )))], clauses: vec![], }), @@ -13496,8 +13521,12 @@ }, ])), parameters: vec![ - Expr::Value((Value::NationalStringLiteral("param1".to_string())).with_empty_span()), - Expr::Value((Value::NationalStringLiteral("param2".to_string())).with_empty_span()), + Expr::Value( + (Value::NationalStringLiteral("param1".to_string().into())).with_empty_span(), + ), + Expr::Value( + (Value::NationalStringLiteral("param2".to_string().into())).with_empty_span(), + ), ], has_parentheses: false, immediate: false, @@ -13541,7 +13570,7 @@ let expected = Statement::Execute { parameters: vec![Expr::Value( - (Value::SingleQuotedString("SELECT 1".to_string())).with_empty_span(), + (Value::SingleQuotedString("SELECT 1".to_string().into())).with_empty_span(), )], immediate: true, using: vec![ExprWithAlias { @@ -13702,7 +13731,7 @@ span: Span::empty(), }, value: Expr::Value( - (Value::SingleQuotedString("AVRO".to_string())).with_empty_span() + (Value::SingleQuotedString("AVRO".to_string().into())).with_empty_span() ) }], query_text: None, @@ -14058,7 +14087,8 @@ left: Box::new(Expr::Identifier(Ident::new("title"))), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - Value::SingleQuotedString("president".to_owned()).with_empty_span(), + Value::SingleQuotedString("president".to_owned().into()) + .with_empty_span(), )), } .into() @@ -14136,7 +14166,8 @@ left: Box::new(Expr::Identifier(Ident::new("title"))), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - Value::SingleQuotedString("president".to_owned()).with_empty_span(), + Value::SingleQuotedString("president".to_owned().into()) + .with_empty_span(), )), } .into() @@ -14197,7 +14228,8 @@ left: Box::new(Expr::Identifier(Ident::new("title"))), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("president".to_owned(),)).with_empty_span() + (Value::SingleQuotedString("president".to_owned().into(),)) + .with_empty_span() )), } .into() @@ -14355,7 +14387,7 @@ negated: false, expr: Box::new(Expr::Identifier(Ident::new("name"))), pattern: Box::new(Expr::Value( - (Value::SingleQuotedString("a%".to_owned())).with_empty_span() + (Value::SingleQuotedString("a%".to_owned().into())).with_empty_span() )), escape_char: None, any: false, @@ -14796,7 +14828,7 @@ opt_replace: Some(ReplaceSelectItem { items: vec![Box::new(ReplaceSelectElement { expr: Expr::Value( - (Value::SingleQuotedString("widget".to_owned())).with_empty_span(), + (Value::SingleQuotedString("widget".to_owned().into())).with_empty_span(), ), column_name: Ident::new("item_name"), as_keyword: true, @@ -14940,13 +14972,13 @@ DictionaryField { key: Ident::with_quote('\'', "Alberta"), value: Box::new(Expr::Value( - (Value::SingleQuotedString("Edmonton".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Edmonton".to_owned().into())).with_empty_span(), )), }, DictionaryField { key: Ident::with_quote('\'', "Manitoba"), value: Box::new(Expr::Value( - (Value::SingleQuotedString("Winnipeg".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Winnipeg".to_owned().into())).with_empty_span(), )), }, ]), @@ -14960,7 +14992,8 @@ value: Box::new(Expr::Cast { kind: CastKind::Cast, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2023-04-01".to_owned())).with_empty_span(), + (Value::SingleQuotedString("2023-04-01".to_owned().into())) + .with_empty_span(), )), data_type: DataType::Timestamp(None, TimezoneInfo::None), format: None, @@ -14971,7 +15004,8 @@ value: Box::new(Expr::Cast { kind: CastKind::Cast, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2023-04-05".to_owned())).with_empty_span(), + (Value::SingleQuotedString("2023-04-05".to_owned().into())) + .with_empty_span(), )), data_type: DataType::Timestamp(None, TimezoneInfo::None), format: None, @@ -14996,18 +15030,18 @@ entries: vec![ MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("Alberta".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Alberta".to_owned().into())).with_empty_span(), )), value: Box::new(Expr::Value( - (Value::SingleQuotedString("Edmonton".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Edmonton".to_owned().into())).with_empty_span(), )), }, MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("Manitoba".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Manitoba".to_owned().into())).with_empty_span(), )), value: Box::new(Expr::Value( - (Value::SingleQuotedString("Winnipeg".to_owned())).with_empty_span(), + (Value::SingleQuotedString("Winnipeg".to_owned().into())).with_empty_span(), )), }, ], @@ -15067,20 +15101,22 @@ entries: vec![ MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("a".to_owned())).with_empty_span(), + (Value::SingleQuotedString("a".to_owned().into())).with_empty_span(), )), value: Box::new(number_expr("10")), }, MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("b".to_owned())).with_empty_span(), + (Value::SingleQuotedString("b".to_owned().into())).with_empty_span(), )), value: Box::new(number_expr("20")), }, ], })), access_chain: vec![AccessExpr::Subscript(Subscript::Index { - index: Expr::Value((Value::SingleQuotedString("a".to_owned())).with_empty_span()), + index: Expr::Value( + (Value::SingleQuotedString("a".to_owned().into())).with_empty_span(), + ), })], }, ); @@ -15093,13 +15129,13 @@ entries: vec![ MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("a".to_owned())).with_empty_span(), + (Value::SingleQuotedString("a".to_owned().into())).with_empty_span(), )), value: Box::new(number_expr("1")), }, MapEntry { key: Box::new(Expr::Value( - (Value::SingleQuotedString("b".to_owned())).with_empty_span(), + (Value::SingleQuotedString("b".to_owned().into())).with_empty_span(), )), value: Box::new(null_expr()), }, @@ -15264,7 +15300,7 @@ expr: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2 seconds".to_string())).with_empty_span() + (Value::SingleQuotedString("2 seconds".to_string().into())).with_empty_span() )), data_type: DataType::Interval { fields: None, @@ -15294,7 +15330,8 @@ expr: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2 seconds".to_string())).with_empty_span(), + (Value::SingleQuotedString("2 seconds".to_string().into())) + .with_empty_span(), )), data_type: DataType::Interval { fields: None, @@ -15352,7 +15389,7 @@ expr: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("2 seconds".to_string())).with_empty_span() + (Value::SingleQuotedString("2 seconds".to_string().into())).with_empty_span() )), data_type: DataType::Interval { fields: None, @@ -15448,7 +15485,7 @@ UtilityOption { name: Ident::new("FORMAT2"), arg: Some(Expr::Value( - (Value::SingleQuotedString("JSON".to_string())).with_empty_span(), + (Value::SingleQuotedString("JSON".to_string().into())).with_empty_span(), )), }, UtilityOption { @@ -15954,13 +15991,15 @@ SqlOption::KeyValue { key: Ident::with_quote('\'', "user"), value: Expr::Value( - (Value::SingleQuotedString("root".to_string())).with_empty_span() + (Value::SingleQuotedString("root".to_string().into())) + .with_empty_span() ) }, SqlOption::KeyValue { key: Ident::with_quote('\'', "password"), value: Expr::Value( - (Value::SingleQuotedString("password".to_string())).with_empty_span() + (Value::SingleQuotedString("password".to_string().into())) + .with_empty_span() ) } ]) @@ -16025,13 +16064,15 @@ SqlOption::KeyValue { key: Ident::with_quote('\'', "user"), value: Expr::Value( - (Value::SingleQuotedString("root".to_string())).with_empty_span() + (Value::SingleQuotedString("root".to_string().into())) + .with_empty_span() ) }, SqlOption::KeyValue { key: Ident::with_quote('\'', "password"), value: Expr::Value( - (Value::SingleQuotedString("password".to_string())).with_empty_span() + (Value::SingleQuotedString("password".to_string().into())) + .with_empty_span() ) } ]) @@ -16582,13 +16623,17 @@ Some(HiveLoadDataFormat { serde: Expr::Value( (Value::SingleQuotedString( - "org.apache.hadoop.hive.serde2.OpenCSVSerde".to_string() + "org.apache.hadoop.hive.serde2.OpenCSVSerde" + .to_string() + .into() )) .with_empty_span() ), input_format: Expr::Value( (Value::SingleQuotedString( - "org.apache.hadoop.mapred.TextInputFormat".to_string() + "org.apache.hadoop.mapred.TextInputFormat" + .to_string() + .into() )) .with_empty_span() ) @@ -17805,10 +17850,12 @@ "array", [ Expr::Value( - (Value::SingleQuotedString("Hello".to_owned())).with_empty_span() + (Value::SingleQuotedString("Hello".to_owned().into())) + .with_empty_span() ), Expr::Value( - (Value::SingleQuotedString("World".to_owned())).with_empty_span() + (Value::SingleQuotedString("World".to_owned().into())) + .with_empty_span() ) ] ), @@ -18028,7 +18075,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::Point), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2".to_string()), + value: Value::SingleQuotedString("1,2".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18041,7 +18088,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::Line), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3,4".to_string()), + value: Value::SingleQuotedString("1,2,3,4".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18054,7 +18101,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::GeometricPath), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3,4".to_string()), + value: Value::SingleQuotedString("1,2,3,4".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18066,7 +18113,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::GeometricBox), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3,4".to_string()), + value: Value::SingleQuotedString("1,2,3,4".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18079,7 +18126,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::Circle), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3".to_string()), + value: Value::SingleQuotedString("1,2,3".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18092,7 +18139,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::Polygon), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3,4".to_string()), + value: Value::SingleQuotedString("1,2,3,4".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -18104,7 +18151,7 @@ Expr::TypedString(TypedString { data_type: DataType::GeometricType(GeometricTypeKind::LineSegment), value: ValueWithSpan { - value: Value::SingleQuotedString("1,2,3,4".to_string()), + value: Value::SingleQuotedString("1,2,3,4".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -19816,7 +19863,8 @@ KeyValueOption { option_name: "PASSWORD".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("secret".to_string()).with_empty_span() + Value::SingleQuotedString("secret".to_string().into()) + .with_empty_span() ), }, KeyValueOption { @@ -19843,13 +19891,15 @@ KeyValueOption { option_name: "t1".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("v1".to_string()).with_empty_span() + Value::SingleQuotedString("v1".to_string().into()) + .with_empty_span() ), }, KeyValueOption { option_name: "t2".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("v2".to_string()).with_empty_span() + Value::SingleQuotedString("v2".to_string().into()) + .with_empty_span() ), }, ] @@ -20519,7 +20569,7 @@ vec![KeyValueOption { option_name: "k1".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("v1".to_string()).with_empty_span() + Value::SingleQuotedString("v1".to_string().into()).with_empty_span() ), },] ); @@ -20557,7 +20607,8 @@ KeyValueOption { option_name: "PASSWORD".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("secret".to_string()).with_empty_span() + Value::SingleQuotedString("secret".to_string().into()) + .with_empty_span() ), }, KeyValueOption { @@ -20596,7 +20647,7 @@ vec![KeyValueOption { option_name: "DEFAULT_SECONDARY_ROLES".to_string(), option_value: KeyValueOptionKind::Multi(vec![Value::SingleQuotedString( - "ALL".to_string() + "ALL".to_string().into() ) .with_empty_span()]) }] @@ -20630,7 +20681,7 @@ option_name: "ARN".to_string(), option_value: KeyValueOptionKind::Single( Value::SingleQuotedString( - "arn:aws:iam::123456789:r1/".to_string() + "arn:aws:iam::123456789:r1/".to_string().into() ) .with_empty_span() ), @@ -21010,7 +21061,7 @@ vec![FunctionArg::Named { name: Ident::new(mode), arg: FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("<a/>".to_string()).into() + Value::SingleQuotedString("<a/>".to_string().into()).into() )), operator: FunctionArgOperator::Space, }] @@ -23037,3 +23088,34 @@ expr_from_projection(&select.projection[0]), ); } + +#[test] +fn string_values_round_trip_decoded_quotes_doubled() { + // A decoded value is re-escaped with a doubled delimiter, so a source + // with adjacent or quote-adjacent-backslash quotes renders byte-exact + let dialects = all_dialects_where(|d| !d.supports_string_literal_backslash_escape()); + dialects.verified_stmt(r#"SELECT 'a''''b'"#); + dialects.verified_stmt(r#"SELECT websearch_to_tsquery('''abc''''def''')"#); + dialects.verified_stmt(r"SELECT 'a\''b'"); + dialects.verified_stmt(r#"SELECT json_valid('" \'' "')"#); +} + +#[test] +fn string_values_print_verbatim_without_unescape() { + // With `with_unescape(false)` the tokenizer keeps the source spelling, so + // `Display` prints string values verbatim instead of re-escaping + let options = ParserOptions::new().with_unescape(false); + let dialects: Vec<Box<dyn Dialect>> = vec![ + Box::new(PostgreSqlDialect {}), + Box::new(SQLiteDialect {}), + Box::new(GenericDialect {}), + ]; + TestedDialects::new_with_options(dialects, options.clone()) + .verified_stmt(r#"SELECT 'a\''''b'"#); + TestedDialects::new_with_options(vec![Box::new(MySqlDialect {})], options.clone()) + .verified_stmt(r#"SELECT 'x''y\'z'"#); + TestedDialects::new_with_options(vec![Box::new(BigQueryDialect {})], options.clone()) + .verified_stmt(r#"SELECT 'a''b'"#); + TestedDialects::new_with_options(vec![Box::new(SnowflakeDialect {})], options) + .verified_stmt(r#"SELECT 'a''b'"#); +}
diff --git a/tests/sqlparser_databricks.rs b/tests/sqlparser_databricks.rs index ce26acc..8f6789a 100644 --- a/tests/sqlparser_databricks.rs +++ b/tests/sqlparser_databricks.rs
@@ -50,7 +50,7 @@ .verified_only_select(r#"SELECT "Ä""#) .projection[0], SelectItem::UnnamedExpr(Expr::Value( - (Value::DoubleQuotedString("Ä".to_owned())).with_empty_span() + (Value::DoubleQuotedString("Ä".to_owned().into())).with_empty_span() )) ); } @@ -120,8 +120,8 @@ call( "array", [ - Expr::value(Value::SingleQuotedString("Hello".to_owned())), - Expr::value(Value::SingleQuotedString("World".to_owned())) + Expr::value(Value::SingleQuotedString("Hello".to_owned().into())), + Expr::value(Value::SingleQuotedString("World".to_owned().into())) ] ), Expr::Lambda(LambdaFunction { @@ -188,11 +188,11 @@ explicit_row: false, rows: vec![ Parens::with_empty_span(vec![ - Expr::Value((Value::DoubleQuotedString("one".to_owned())).with_empty_span()), + Expr::Value((Value::DoubleQuotedString("one".to_owned().into())).with_empty_span()), Expr::value(number("1")), ]), Parens::with_empty_span(vec![ - Expr::Value((Value::SingleQuotedString("two".to_owned())).with_empty_span()), + Expr::Value((Value::SingleQuotedString("two".to_owned().into())).with_empty_span()), Expr::value(number("2")), ]), ], @@ -381,7 +381,9 @@ SelectItem::UnnamedExpr(Expr::Struct { values: vec![ Expr::value(number("1")), - Expr::Value((Value::SingleQuotedString("foo".to_string())).with_empty_span()) + Expr::Value( + (Value::SingleQuotedString("foo".to_string().into())).with_empty_span() + ) ], fields: vec![] }) @@ -398,7 +400,7 @@ }, Expr::Named { expr: Expr::Value( - (Value::SingleQuotedString("foo".to_string())).with_empty_span() + (Value::SingleQuotedString("foo".to_string().into())).with_empty_span() ) .into(), name: Ident::new("foo") @@ -418,7 +420,7 @@ Expr::TypedString(TypedString { data_type: DataType::TimestampNtz(None), value: ValueWithSpan { - value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned()), + value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned().into()), span: Span::empty(), }, uses_odbc_syntax: false @@ -773,7 +775,7 @@ #[test] fn parse_databricks_query_entry_points() { databricks().verified_stmt("CREATE TABLE t (attrs MAP<STRING, ARRAY<INT>>)"); - databricks().one_statement_parses_to(r#"SELECT 'it\'s'"#, "SELECT 'it''s'"); + databricks().verified_stmt(r#"SELECT 'it\'s'"#); databricks().verified_stmt("SELECT * REPLACE (upper(name) AS name) FROM source"); databricks().verified_stmt( "CREATE VIEW cross_product AS FROM main.raw.left_table, main.raw.right_table",
diff --git a/tests/sqlparser_duckdb.rs b/tests/sqlparser_duckdb.rs index 438bbce..f1a7601 100644 --- a/tests/sqlparser_duckdb.rs +++ b/tests/sqlparser_duckdb.rs
@@ -429,7 +429,7 @@ elem: vec![Expr::Dictionary(vec![DictionaryField { key: Ident::with_quote('\'', "a"), value: Box::new(Expr::Value( - (Value::SingleQuotedString("abc".to_string())).with_empty_span() + (Value::SingleQuotedString("abc".to_string().into())).with_empty_span() )), },],)], named: false @@ -464,7 +464,7 @@ DictionaryField { key: Ident::with_quote('\'', "b"), value: Expr::Value( - (Value::SingleQuotedString("abc".to_string())).with_empty_span() + (Value::SingleQuotedString("abc".to_string().into())).with_empty_span() ) .into(), }, @@ -647,14 +647,14 @@ FunctionArg::Named { name: Ident::new("a"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("1".to_owned())).with_empty_span() + (Value::SingleQuotedString("1".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::Assignment }, FunctionArg::Named { name: Ident::new("b"), arg: FunctionArgExpr::Expr(Expr::Value( - (Value::SingleQuotedString("2".to_owned())).with_empty_span() + (Value::SingleQuotedString("2".to_owned().into())).with_empty_span() )), operator: FunctionArgOperator::Assignment }, @@ -684,9 +684,15 @@ &Expr::CompoundFieldAccess { root: Box::new(Expr::Array(Array { elem: vec![ - Expr::Value((Value::SingleQuotedString("a".to_owned())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("b".to_owned())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("c".to_owned())).with_empty_span()) + Expr::Value( + (Value::SingleQuotedString("a".to_owned().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("b".to_owned().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("c".to_owned().into())).with_empty_span() + ) ], named: false })), @@ -870,12 +876,12 @@ assert_eq!( &Expr::Trim { expr: Box::new(Expr::Value( - Value::SingleQuotedString("xyz".to_owned()).with_empty_span() + Value::SingleQuotedString("xyz".to_owned().into()).with_empty_span() )), trim_where: None, trim_what: None, trim_characters: Some(vec![Expr::Value( - Value::SingleQuotedString("a".to_owned()).with_empty_span() + Value::SingleQuotedString("a".to_owned().into()).with_empty_span() )]), }, expr_from_projection(only(&select.projection))
diff --git a/tests/sqlparser_hive.rs b/tests/sqlparser_hive.rs index 355fd5c..f46523b 100644 --- a/tests/sqlparser_hive.rs +++ b/tests/sqlparser_hive.rs
@@ -418,7 +418,7 @@ function_body, Some(CreateFunctionBody::AsBeforeOptions { body: Expr::Value( - (Value::SingleQuotedString("org.random.class.Name".to_string())) + (Value::SingleQuotedString("org.random.class.Name".to_string().into())) .with_empty_span() ), link_symbol: None,
diff --git a/tests/sqlparser_mssql.rs b/tests/sqlparser_mssql.rs index 2e2f0cd..639db09 100644 --- a/tests/sqlparser_mssql.rs +++ b/tests/sqlparser_mssql.rs
@@ -69,7 +69,7 @@ args: None, with_hints: vec![], version: Some(TableVersion::ForSystemTimeAsOf(Expr::Value( - (Value::SingleQuotedString(version)).with_empty_span() + (Value::SingleQuotedString(version.into())).with_empty_span() ))), partitions: vec![], with_ordinality: false, @@ -1431,7 +1431,7 @@ }], data_type: Some(Text), assignment: Some(MsSqlAssignment(Box::new(Expr::Value( - (SingleQuotedString("foobar".to_string())).with_empty_span() + (SingleQuotedString("foobar".to_string().into())).with_empty_span() )))), declare_type: None, binary: None, @@ -1577,7 +1577,7 @@ conditional_statements: ConditionalStatements::Sequence { statements: vec![Statement::Print(PrintStatement { message: Box::new(Expr::Value( - (Value::SingleQuotedString("Hello World".to_string())) + (Value::SingleQuotedString("Hello World".to_string().into())) .with_empty_span() )), })], @@ -1612,7 +1612,7 @@ s, Statement::RaisError { message: Box::new(Expr::Value( - (Value::SingleQuotedString("This is a test".to_string())).with_empty_span() + (Value::SingleQuotedString("This is a test".to_string().into())).with_empty_span() )), severity: Box::new(Expr::Value( (Value::Number("16".parse().unwrap(), false)).with_empty_span() @@ -1653,7 +1653,8 @@ (Value::Number("51000".parse().unwrap(), false)).with_empty_span() ))), message: Some(Box::new(Expr::Value( - (Value::SingleQuotedString("Record does not exist.".to_string())).with_empty_span() + (Value::SingleQuotedString("Record does not exist.".to_string().into())) + .with_empty_span() ))), state: Some(Box::new(Expr::Value( (Value::Number("1".parse().unwrap(), false)).with_empty_span() @@ -1688,7 +1689,7 @@ Statement::WaitFor(WaitForStatement { wait_type: WaitForType::Delay, expr: Expr::Value( - (Value::SingleQuotedString("00:00:05".to_string())).with_empty_span() + (Value::SingleQuotedString("00:00:05".to_string().into())).with_empty_span() ), }) ); @@ -1701,7 +1702,7 @@ Statement::WaitFor(WaitForStatement { wait_type: WaitForType::Time, expr: Expr::Value( - (Value::SingleQuotedString("14:30:00".to_string())).with_empty_span() + (Value::SingleQuotedString("14:30:00".to_string().into())).with_empty_span() ), }) ); @@ -2496,7 +2497,7 @@ statements: Some(ConditionalStatements::Sequence { statements: vec![Statement::RaisError { message: Box::new(Expr::Value( - (Value::SingleQuotedString("Notify Customer Relations".to_string())) + (Value::SingleQuotedString("Notify Customer Relations".to_string().into())) .with_empty_span() )), severity: Box::new(Expr::Value( @@ -2586,7 +2587,7 @@ print_stmt, Statement::Print(PrintStatement { message: Box::new(Expr::Value( - (Value::SingleQuotedString("Hello, world!".to_string())).with_empty_span() + (Value::SingleQuotedString("Hello, world!".to_string().into())).with_empty_span() )), }) );
diff --git a/tests/sqlparser_mysql.rs b/tests/sqlparser_mysql.rs index b69ba95..b130291 100644 --- a/tests/sqlparser_mysql.rs +++ b/tests/sqlparser_mysql.rs
@@ -52,11 +52,11 @@ let select = mysql().verified_only_select(sql); assert_eq!(2, select.projection.len()); assert_eq!( - &Expr::Value((Value::SingleQuotedString("single".to_string())).with_empty_span()), + &Expr::Value((Value::SingleQuotedString("single".to_string().into())).with_empty_span()), expr_from_projection(&select.projection[0]) ); assert_eq!( - &Expr::Value((Value::DoubleQuotedString("double".to_string())).with_empty_span()), + &Expr::Value((Value::DoubleQuotedString("double".to_string().into())).with_empty_span()), expr_from_projection(&select.projection[1]) ); } @@ -904,7 +904,7 @@ left: Box::new(Expr::Identifier(Ident::new("col"))), op: BinaryOperator::LongArrow, right: Box::new(Expr::Value( - Value::SingleQuotedString("$.id".to_string()).with_empty_span() + Value::SingleQuotedString("$.id".to_string().into()).with_empty_span() )), }), data_type: DataType::Unsigned, @@ -921,7 +921,7 @@ left: Box::new(Expr::Identifier(Ident::new("col"))), op: BinaryOperator::LongArrow, right: Box::new(Expr::Value( - Value::SingleQuotedString("$.fields".to_string()).with_empty_span() + Value::SingleQuotedString("$.fields".to_string().into()).with_empty_span() )), }), data_type: DataType::Array(ArrayElemTypeDef::Qualified( @@ -1163,11 +1163,11 @@ })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("COMPRESSION"), - value: Expr::value(Value::SingleQuotedString("ZLIB".to_owned())) + value: Expr::value(Value::SingleQuotedString("ZLIB".to_owned().into())) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("ENCRYPTION"), - value: Expr::value(Value::SingleQuotedString("Y".to_owned())) + value: Expr::value(Value::SingleQuotedString("Y".to_owned().into())) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("MAX_ROWS"), @@ -1191,19 +1191,25 @@ })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("CONNECTION"), - value: Expr::value(Value::SingleQuotedString("mysql://localhost".to_owned())) + value: Expr::value(Value::SingleQuotedString( + "mysql://localhost".to_owned().into() + )) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("ENGINE_ATTRIBUTE"), - value: Expr::value(Value::SingleQuotedString("primary".to_owned())) + value: Expr::value(Value::SingleQuotedString("primary".to_owned().into())) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("PASSWORD"), - value: Expr::value(Value::SingleQuotedString("secure_password".to_owned())) + value: Expr::value(Value::SingleQuotedString( + "secure_password".to_owned().into() + )) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("SECONDARY_ENGINE_ATTRIBUTE"), - value: Expr::value(Value::SingleQuotedString("secondary_attr".to_owned())) + value: Expr::value(Value::SingleQuotedString( + "secondary_attr".to_owned().into() + )) })); assert!(plain_options.contains(&SqlOption::Ident(Ident::new( "START TRANSACTION".to_owned() @@ -1229,11 +1235,15 @@ assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("DATA DIRECTORY"), - value: Expr::value(Value::SingleQuotedString("/var/lib/mysql/data".to_owned())) + value: Expr::value(Value::SingleQuotedString( + "/var/lib/mysql/data".to_owned().into() + )) })); assert!(plain_options.contains(&SqlOption::KeyValue { key: Ident::new("INDEX DIRECTORY"), - value: Expr::value(Value::SingleQuotedString("/var/lib/mysql/index".to_owned())) + value: Expr::value(Value::SingleQuotedString( + "/var/lib/mysql/index".to_owned().into() + )) })); } _ => unreachable!(), @@ -2017,21 +2027,23 @@ rows: vec![ Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Some Inserts".to_string())) - .with_empty_span() + (Value::SingleQuotedString( + "Test Some Inserts".to_string().into() + )) + .with_empty_span() ), Expr::value(number("1")) ]), Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Entry 2".to_string())) + (Value::SingleQuotedString("Test Entry 2".to_string().into())) .with_empty_span() ), Expr::value(number("2")) ]), Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Entry 3".to_string())) + (Value::SingleQuotedString("Test Entry 3".to_string().into())) .with_empty_span() ), Expr::value(number("3")) @@ -2088,7 +2100,7 @@ explicit_row: false, rows: vec![Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Some Inserts".to_string())) + (Value::SingleQuotedString("Test Some Inserts".to_string().into())) .with_empty_span() ), Expr::value(number("1")) @@ -2144,7 +2156,7 @@ explicit_row: false, rows: vec![Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Some Inserts".to_string())) + (Value::SingleQuotedString("Test Some Inserts".to_string().into())) .with_empty_span() ), Expr::value(number("1")) @@ -2197,7 +2209,7 @@ explicit_row: false, rows: vec![Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Some Inserts".to_string())) + (Value::SingleQuotedString("Test Some Inserts".to_string().into())) .with_empty_span() ), Expr::value(number("1")) @@ -2252,7 +2264,8 @@ value_keyword: false, explicit_row: false, rows: vec![Parens::with_empty_span(vec![Expr::Value( - (Value::SingleQuotedString("2024-01-01".to_string())).with_empty_span() + (Value::SingleQuotedString("2024-01-01".to_string().into())) + .with_empty_span() )])] })), order_by: None, @@ -2317,7 +2330,7 @@ rows: vec![Parens::with_empty_span(vec![ Expr::value(number("1")), Expr::Value( - (Value::SingleQuotedString("2024-01-01".to_string())) + (Value::SingleQuotedString("2024-01-01".to_string().into())) .with_empty_span() ) ])] @@ -2373,7 +2386,7 @@ explicit_row: false, rows: vec![Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("Test Some Inserts".to_string())) + (Value::SingleQuotedString("Test Some Inserts".to_string().into())) .with_empty_span() ), Expr::value(number("1")) @@ -2475,12 +2488,14 @@ explicit_row: false, rows: vec![Parens::with_empty_span(vec![ Expr::Value( - (Value::SingleQuotedString("accounting_manager".to_string())) - .with_empty_span() + (Value::SingleQuotedString( + "accounting_manager".to_string().into() + )) + .with_empty_span() ), Expr::Value( (Value::SingleQuotedString( - "Some description about the group".to_string() + "Some description about the group".to_string().into() )) .with_empty_span() ), @@ -2868,7 +2883,7 @@ ])), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("Peter".to_string())).with_empty_span() + (Value::SingleQuotedString("Peter".to_string().into())).with_empty_span() )) }), selection @@ -3522,11 +3537,24 @@ #[test] fn parse_like_with_escape() { - // verify backslash is not stripped for escaped wildcards - mysql().verified_only_select(r#"SELECT 'a\%c' LIKE 'a\%c'"#); - mysql().verified_only_select(r#"SELECT 'a\_c' LIKE 'a\_c'"#); - mysql().verified_only_select(r#"SELECT '%\_\%' LIKE '%\_\%'"#); - mysql().verified_only_select(r#"SELECT '\_\%' LIKE CONCAT('\_', '\%')"#); + // verify backslash is not stripped for escaped wildcards, which a + // backslash-escape dialect then re-escapes as `\\` + mysql().one_statement_parses_to( + r#"SELECT 'a\%c' LIKE 'a\%c'"#, + r#"SELECT 'a\\%c' LIKE 'a\\%c'"#, + ); + mysql().one_statement_parses_to( + r#"SELECT 'a\_c' LIKE 'a\_c'"#, + r#"SELECT 'a\\_c' LIKE 'a\\_c'"#, + ); + mysql().one_statement_parses_to( + r#"SELECT '%\_\%' LIKE '%\_\%'"#, + r#"SELECT '%\\_\\%' LIKE '%\\_\\%'"#, + ); + mysql().one_statement_parses_to( + r#"SELECT '\_\%' LIKE CONCAT('\_', '\%')"#, + r#"SELECT '\\_\\%' LIKE CONCAT('\\_', '\\%')"#, + ); mysql().verified_only_select(r#"SELECT 'a%c' LIKE 'a$%c' ESCAPE '$'"#); mysql().verified_only_select(r#"SELECT 'a_c' LIKE 'a#_c' ESCAPE '#'"#); } @@ -3792,7 +3820,7 @@ projection: vec![SelectItem::UnnamedExpr(Expr::Prefixed { prefix: Ident::from("_latin1"), value: Expr::Value( - Value::HexStringLiteral("4D7953514C".to_string()).with_empty_span() + Value::HexStringLiteral("4D7953514C".to_string().into()).with_empty_span() ) .into(), })], @@ -4000,7 +4028,10 @@ r#"SELECT * FROM JSON_TABLE(?, '$[*]' COLUMNS(a VARCHAR(20) PATH '$')) AS t"#, ); // quote escaping - mysql().verified_only_select(r#"SELECT * FROM JSON_TABLE('{"''": [1,2,3]}', '$."''"[*]' COLUMNS(a VARCHAR(20) PATH '$')) AS t"#); + mysql().one_statement_parses_to( + r#"SELECT * FROM JSON_TABLE('{"''": [1,2,3]}', '$."''"[*]' COLUMNS(a VARCHAR(20) PATH '$')) AS t"#, + r#"SELECT * FROM JSON_TABLE('{"\'": [1,2,3]}', '$."\'"[*]' COLUMNS(a VARCHAR(20) PATH '$')) AS t"#, + ); // double quotes mysql().verified_only_select( r#"SELECT * FROM JSON_TABLE("[]", "$[*]" COLUMNS(a VARCHAR(20) PATH "$")) AS t"#, @@ -4029,15 +4060,15 @@ .from[0] .relation, TableFactor::JsonTable { - json_expr: Expr::Value((Value::SingleQuotedString("[1,2]".to_string())).with_empty_span()), - json_path: Value::SingleQuotedString("$[*]".to_string()).with_empty_span(), + json_expr: Expr::Value((Value::SingleQuotedString("[1,2]".to_string().into())).with_empty_span()), + json_path: Value::SingleQuotedString("$[*]".to_string().into()).with_empty_span(), columns: vec![ JsonTableColumn::Named(JsonTableNamedColumn { name: Ident::new("x"), r#type: DataType::Int(None), - path: Value::SingleQuotedString("$".to_string()).with_empty_span(), + path: Value::SingleQuotedString("$".to_string().into()).with_empty_span(), exists: false, - on_empty: Some(JsonTableColumnErrorHandling::Default(Value::SingleQuotedString("0".to_string()).with_empty_span())), + on_empty: Some(JsonTableColumnErrorHandling::Default(Value::SingleQuotedString("0".to_string().into()).with_empty_span())), on_error: Some(JsonTableColumnErrorHandling::Null), }), ], @@ -4102,7 +4133,7 @@ assert_eq!( select.projection, vec![SelectItem::UnnamedExpr(Expr::Value( - (Value::SingleQuotedByteStringLiteral("111".to_string())).with_empty_span() + (Value::SingleQuotedByteStringLiteral("111".to_string().into())).with_empty_span() ))] ); } @@ -4491,7 +4522,7 @@ ); assert_eq!( match_value, - Value::SingleQuotedString("AAA".to_owned()).with_empty_span() + Value::SingleQuotedString("AAA".to_owned().into()).with_empty_span() ); assert_eq!(opt_search_modifier, Some(SearchModifier::InBooleanMode)); } @@ -4874,11 +4905,13 @@ select.projection, vec![SelectItem::UnnamedExpr(Expr::MemberOf(MemberOf { value: Box::new(Expr::Value( - Value::SingleQuotedString("ab".to_string()).into() + Value::SingleQuotedString("ab".to_string().into()).into() )), array: Box::new(Expr::Value( - Value::SingleQuotedString(r#"[23, "abc", 17, "ab", 10]"#.to_string()) - .into() + Value::SingleQuotedString( + r#"[23, "abc", 17, "ab", 10]"#.to_string().into() + ) + .into() )), }))] ); @@ -5302,3 +5335,15 @@ )), ); } + +#[test] +fn string_values_re_escape_decoded_quotes_with_backslash() { + // MySQL string literals use backslash escapes, so a decoded value that + // contains a quote or a backslash is printed with `\'` and `\\` + // https://dev.mysql.com/doc/refman/8.0/en/string-literals.html + mysql().one_statement_parses_to(r#"SELECT 'a''b'"#, r"SELECT 'a\'b'"); + mysql().verified_stmt(r"SELECT 'a\'b'"); + mysql().verified_stmt(r"SELECT 'a\\b'"); + mysql().one_statement_parses_to(r#"SELECT "a""b""#, r#"SELECT "a\"b""#); + mysql().verified_stmt(r#"SELECT "a\"b""#); +}
diff --git a/tests/sqlparser_postgres.rs b/tests/sqlparser_postgres.rs index fa6b412..e8f08b1 100644 --- a/tests/sqlparser_postgres.rs +++ b/tests/sqlparser_postgres.rs
@@ -1086,7 +1086,8 @@ SqlOption::KeyValue { key: Ident::new("lc_collate"), value: Expr::Value( - Value::SingleQuotedString("en_US.utf8".to_string()).with_empty_span(), + Value::SingleQuotedString("en_US.utf8".to_string().into()) + .with_empty_span(), ), }, ]), @@ -1118,7 +1119,8 @@ SqlOption::KeyValue { key: Ident::new("locale"), value: Expr::Value( - Value::SingleQuotedString("nonsense-nowhere".to_string()).with_empty_span(), + Value::SingleQuotedString("nonsense-nowhere".to_string().into()) + .with_empty_span(), ), }, ]), @@ -1247,7 +1249,7 @@ AlterTableOperation::AlterColumn { column_name, op } => { assert_eq!("is_active", column_name.to_string()); let using_expr = - Expr::Value(Value::SingleQuotedString("text".to_string()).with_empty_span()); + Expr::Value(Value::SingleQuotedString("text".to_string().into()).with_empty_span()); assert_eq!( op, AlterColumnOperation::SetDataType { @@ -2446,7 +2448,7 @@ name: Some(ObjectName::from(vec!["a".into()])), parameters: vec![ Expr::value(number("1")), - Expr::Value((Value::SingleQuotedString("t".to_string())).with_empty_span()) + Expr::Value((Value::SingleQuotedString("t".to_string().into())).with_empty_span()) ], has_parentheses: true, using: vec![], @@ -4052,7 +4054,9 @@ statement, Statement::Set(Set::SetTransaction { modes: vec![], - snapshot: Some(Value::SingleQuotedString(String::from("000003A1-1")).with_empty_span()), + snapshot: Some( + Value::SingleQuotedString(String::from("000003A1-1").into()).with_empty_span() + ), session: false }) ); @@ -4080,7 +4084,7 @@ left: Box::new(Expr::Identifier(Ident::new("params"))), op: BinaryOperator::LongArrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("name".to_string())).with_empty_span() + (Value::SingleQuotedString("name".to_string().into())).with_empty_span() )), }), select.projection[0] @@ -4093,7 +4097,7 @@ left: Box::new(Expr::Identifier(Ident::new("params"))), op: BinaryOperator::Arrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("name".to_string())).with_empty_span() + (Value::SingleQuotedString("name".to_string().into())).with_empty_span() )), }), select.projection[0] @@ -4107,12 +4111,12 @@ left: Box::new(Expr::Identifier(Ident::new("info"))), op: BinaryOperator::Arrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("items".to_string())).with_empty_span() + (Value::SingleQuotedString("items".to_string().into())).with_empty_span() )) }), op: BinaryOperator::LongArrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("product".to_string())).with_empty_span() + (Value::SingleQuotedString("product".to_string().into())).with_empty_span() )), }), select.projection[0] @@ -4165,7 +4169,7 @@ left: Box::new(Expr::Identifier(Ident::new("info"))), op: BinaryOperator::HashArrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("{a,b,c}".to_string())).with_empty_span() + (Value::SingleQuotedString("{a,b,c}".to_string().into())).with_empty_span() )), }), select.projection[0] @@ -4178,7 +4182,7 @@ left: Box::new(Expr::Identifier(Ident::new("info"))), op: BinaryOperator::HashLongArrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("{a,b,c}".to_string())).with_empty_span() + (Value::SingleQuotedString("{a,b,c}".to_string().into())).with_empty_span() )), }), select.projection[0] @@ -4191,7 +4195,7 @@ left: Box::new(Expr::Identifier(Ident::new("info"))), op: BinaryOperator::AtArrow, right: Box::new(Expr::Value( - (Value::SingleQuotedString("{\"a\": 1}".to_string())).with_empty_span() + (Value::SingleQuotedString("{\"a\": 1}".to_string().into())).with_empty_span() )), }, select.selection.unwrap(), @@ -4202,7 +4206,7 @@ assert_eq!( Expr::BinaryOp { left: Box::new(Expr::Value( - (Value::SingleQuotedString("{\"a\": 1}".to_string())).with_empty_span() + (Value::SingleQuotedString("{\"a\": 1}".to_string().into())).with_empty_span() )), op: BinaryOperator::ArrowAt, right: Box::new(Expr::Identifier(Ident::new("info"))), @@ -4218,8 +4222,12 @@ op: BinaryOperator::HashMinus, right: Box::new(Expr::Array(Array { elem: vec![ - Expr::Value((Value::SingleQuotedString("a".to_string())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("b".to_string())).with_empty_span()), + Expr::Value( + (Value::SingleQuotedString("a".to_string().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("b".to_string().into())).with_empty_span() + ), ], named: true, })), @@ -4234,7 +4242,7 @@ left: Box::new(Expr::Identifier(Ident::from("info"))), op: BinaryOperator::AtQuestion, right: Box::new(Expr::Value( - (Value::SingleQuotedString("$.a".to_string())).with_empty_span() + (Value::SingleQuotedString("$.a".to_string().into())).with_empty_span() ),), }, select.selection.unwrap(), @@ -4247,7 +4255,7 @@ left: Box::new(Expr::Identifier(Ident::from("info"))), op: BinaryOperator::AtAt, right: Box::new(Expr::Value( - (Value::SingleQuotedString("$.a".to_string())).with_empty_span() + (Value::SingleQuotedString("$.a".to_string().into())).with_empty_span() ),), }, select.selection.unwrap(), @@ -4260,7 +4268,7 @@ left: Box::new(Expr::Identifier(Ident::new("info"))), op: BinaryOperator::Question, right: Box::new(Expr::Value( - (Value::SingleQuotedString("b".to_string())).with_empty_span() + (Value::SingleQuotedString("b".to_string().into())).with_empty_span() )), }, select.selection.unwrap(), @@ -4274,8 +4282,12 @@ op: BinaryOperator::QuestionAnd, right: Box::new(Expr::Array(Array { elem: vec![ - Expr::Value((Value::SingleQuotedString("b".to_string())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("c".to_string())).with_empty_span()) + Expr::Value( + (Value::SingleQuotedString("b".to_string().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("c".to_string().into())).with_empty_span() + ) ], named: true })) @@ -4291,8 +4303,12 @@ op: BinaryOperator::QuestionPipe, right: Box::new(Expr::Array(Array { elem: vec![ - Expr::Value((Value::SingleQuotedString("b".to_string())).with_empty_span()), - Expr::Value((Value::SingleQuotedString("c".to_string())).with_empty_span()) + Expr::Value( + (Value::SingleQuotedString("b".to_string().into())).with_empty_span() + ), + Expr::Value( + (Value::SingleQuotedString("c".to_string().into())).with_empty_span() + ) ], named: true })) @@ -4468,10 +4484,12 @@ Array { elem: vec![ Expr::Value( - (Value::SingleQuotedString("i".to_string())).with_empty_span() + (Value::SingleQuotedString("i".to_string().into())) + .with_empty_span() ), Expr::Value( - (Value::SingleQuotedString("i".to_string())).with_empty_span() + (Value::SingleQuotedString("i".to_string().into())) + .with_empty_span() ), ], named: true @@ -4561,7 +4579,10 @@ }) => { assert_eq!(name.to_string(), "xml"); assert!(modifiers.is_empty()); - assert_eq!(value.value, Value::SingleQuotedString("<foo/>".to_string())); + assert_eq!( + value.value, + Value::SingleQuotedString("<foo/>".to_string().into()) + ); } other => panic!("Expected TypedString, got: {other:?}"), } @@ -6767,7 +6788,8 @@ rows: vec![Parens::with_empty_span(vec![ Expr::Identifier(Ident::new("DEFAULT")), Expr::Value( - (Value::SingleQuotedString("0123".to_string())).with_empty_span() + (Value::SingleQuotedString("0123".to_string().into())) + .with_empty_span() ) ])] })), @@ -6840,7 +6862,7 @@ timestamp: Box::new(Expr::TypedString(TypedString { data_type: DataType::Timestamp(None, TimezoneInfo::None), value: ValueWithSpan { - value: Value::SingleQuotedString("2001-09-28 01:00".to_string()), + value: Value::SingleQuotedString("2001-09-28 01:00".to_string().into()), span: Span::empty(), }, uses_odbc_syntax: false, @@ -6848,7 +6870,8 @@ time_zone: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - Value::SingleQuotedString("America/Los_Angeles".to_owned()).with_empty_span(), + Value::SingleQuotedString("America/Los_Angeles".to_owned().into()) + .with_empty_span(), )), data_type: DataType::Text, format: None, @@ -6857,7 +6880,7 @@ op: BinaryOperator::Plus, right: Box::new(Expr::Interval(Interval { value: Box::new(Expr::Value( - Value::SingleQuotedString("23 hours".to_owned()).with_empty_span(), + Value::SingleQuotedString("23 hours".to_owned().into()).with_empty_span(), )), leading_field: None, leading_precision: None, @@ -7677,12 +7700,12 @@ })), op: arrow_operator, right: Box::new(Expr::Value( - (Value::SingleQuotedString("bar".to_string())).with_empty_span() + (Value::SingleQuotedString("bar".to_string().into())).with_empty_span() )), }), op: BinaryOperator::Eq, right: Box::new(Expr::Value( - (Value::SingleQuotedString("spam".to_string())).with_empty_span() + (Value::SingleQuotedString("spam".to_string().into())).with_empty_span() )), } ) @@ -7715,7 +7738,7 @@ right: Box::new(Expr::Cast { kind: CastKind::DoubleColon, expr: Box::new(Expr::Value( - (Value::SingleQuotedString("bar".to_string())).with_empty_span() + (Value::SingleQuotedString("bar".to_string().into())).with_empty_span() )), data_type: DataType::Text, format: None, @@ -7843,7 +7866,7 @@ assert_eq!( select.projection, vec![SelectItem::UnnamedExpr(Expr::Value( - (Value::SingleQuotedByteStringLiteral("111".to_string())).with_empty_span() + (Value::SingleQuotedByteStringLiteral("111".to_string().into())).with_empty_span() ))] ); } @@ -10965,7 +10988,7 @@ ObjectName::from(vec!["public".into(), "mood".into()]), vec![] ), - value: Value::SingleQuotedString("happy".to_string()).with_empty_span(), + value: Value::SingleQuotedString("happy".to_string().into()).with_empty_span(), uses_odbc_syntax: false, }) ); @@ -11575,7 +11598,7 @@ assert_eq!( expr_from_projection(&pg().verified_only_select("SELECT X'1F'").projection[0]), - &Expr::Value(Value::HexStringLiteral("1F".to_string()).with_empty_span()) + &Expr::Value(Value::HexStringLiteral("1F".to_string().into()).with_empty_span()) ); for (sql, message) in [
diff --git a/tests/sqlparser_redshift.rs b/tests/sqlparser_redshift.rs index 38f46b2..f3223af 100644 --- a/tests/sqlparser_redshift.rs +++ b/tests/sqlparser_redshift.rs
@@ -183,7 +183,7 @@ }, JsonPathElem::Bracket { key: Expr::Value( - (Value::SingleQuotedString("id".to_owned())).with_empty_span() + (Value::SingleQuotedString("id".to_owned().into())).with_empty_span() ) } ] @@ -209,7 +209,7 @@ }, JsonPathElem::Bracket { key: Expr::Value( - (Value::SingleQuotedString("id".to_owned())).with_empty_span() + (Value::SingleQuotedString("id".to_owned().into())).with_empty_span() ) } ] @@ -370,7 +370,7 @@ #[test] fn parse_string_literal_backslash_escape() { - redshift().one_statement_parses_to(r#"SELECT 'l\'auto'"#, "SELECT 'l''auto'"); + redshift().verified_stmt(r#"SELECT 'l\'auto'"#); } #[test]
diff --git a/tests/sqlparser_snowflake.rs b/tests/sqlparser_snowflake.rs index 5e3cbc8..f86dbf6 100644 --- a/tests/sqlparser_snowflake.rs +++ b/tests/sqlparser_snowflake.rs
@@ -1793,7 +1793,9 @@ Some(DeclareAssignment::Expr( Expr::Tuple(vec![ Expr::value(number("42")), - Expr::Value((Value::SingleQuotedString("ERROR".to_string())).with_empty_span()), + Expr::Value( + (Value::SingleQuotedString("ERROR".to_string().into())).with_empty_span(), + ), ]) .into(), )), @@ -1991,25 +1993,25 @@ assert!(stage_params.credentials.options.contains(&KeyValueOption { option_name: "AWS_KEY_ID".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("1a2b3c".to_string()).with_empty_span() + Value::SingleQuotedString("1a2b3c".to_string().into()).with_empty_span() ), })); assert!(stage_params.credentials.options.contains(&KeyValueOption { option_name: "AWS_SECRET_KEY".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("4x5y6z".to_string()).with_empty_span() + Value::SingleQuotedString("4x5y6z".to_string().into()).with_empty_span() ), })); assert!(stage_params.encryption.options.contains(&KeyValueOption { option_name: "MASTER_KEY".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("key".to_string()).with_empty_span() + Value::SingleQuotedString("key".to_string().into()).with_empty_span() ), })); assert!(stage_params.encryption.options.contains(&KeyValueOption { option_name: "TYPE".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("AWS_SSE_KMS".to_string()).with_empty_span() + Value::SingleQuotedString("AWS_SSE_KMS".to_string().into()).with_empty_span() ), })); } @@ -2043,7 +2045,7 @@ assert!(directory_table_params.options.contains(&KeyValueOption { option_name: "NOTIFICATION_INTEGRATION".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("some-string".to_string()).with_empty_span() + Value::SingleQuotedString("some-string".to_string().into()).with_empty_span() ), })); } @@ -2077,7 +2079,11 @@ assert!(file_format.options.contains(&KeyValueOption { option_name: "ESCAPE".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString(r#"\\"#.to_string()).with_empty_span() + Value::SingleQuotedString(QuotedString { + value: r#"\\"#.to_string(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() ), })); } @@ -2183,7 +2189,7 @@ assert!(options.options.contains(&KeyValueOption { option_name: "FIELD_DELIMITER".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("|".to_string()).with_empty_span() + Value::SingleQuotedString("|".to_string().into()).with_empty_span() ), })); assert!(options.options.contains(&KeyValueOption { @@ -2361,25 +2367,25 @@ assert!(stage_params.credentials.options.contains(&KeyValueOption { option_name: "AWS_KEY_ID".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("1a2b3c".to_string()).with_empty_span() + Value::SingleQuotedString("1a2b3c".to_string().into()).with_empty_span() ), })); assert!(stage_params.credentials.options.contains(&KeyValueOption { option_name: "AWS_SECRET_KEY".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("4x5y6z".to_string()).with_empty_span() + Value::SingleQuotedString("4x5y6z".to_string().into()).with_empty_span() ), })); assert!(stage_params.encryption.options.contains(&KeyValueOption { option_name: "MASTER_KEY".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("key".to_string()).with_empty_span() + Value::SingleQuotedString("key".to_string().into()).with_empty_span() ), })); assert!(stage_params.encryption.options.contains(&KeyValueOption { option_name: "TYPE".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString("AWS_SSE_KMS".to_string()).with_empty_span() + Value::SingleQuotedString("AWS_SSE_KMS".to_string().into()).with_empty_span() ), })); } @@ -2500,7 +2506,9 @@ assert_eq!( from_transformations.as_ref().unwrap()[4], StageLoadSelectItemKind::SelectItem(SelectItem::ExprWithAlias { - expr: Expr::Value(Value::SingleQuotedString("5".parse().unwrap()).into()), + expr: Expr::Value( + Value::SingleQuotedString("5".parse::<String>().unwrap().into()).into() + ), alias: Ident::new("const_str".to_string()) }) ); @@ -2590,7 +2598,11 @@ assert!(file_format.options.contains(&KeyValueOption { option_name: "ESCAPE".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString(r#"\\"#.to_string()).with_empty_span() + Value::SingleQuotedString(QuotedString { + value: r#"\\"#.to_string(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() ), })); } @@ -2632,7 +2644,11 @@ assert!(file_format.options.contains(&KeyValueOption { option_name: "ESCAPE".to_string(), option_value: KeyValueOptionKind::Single( - Value::SingleQuotedString(r#"\\"#.to_string()).with_empty_span() + Value::SingleQuotedString(QuotedString { + value: r#"\\"#.to_string(), + escaping: QuoteEscaping::Raw, + }) + .with_empty_span() ), })); } @@ -2819,12 +2835,12 @@ assert_eq!( &Expr::Trim { expr: Box::new(Expr::Value( - (Value::SingleQuotedString("xyz".to_owned())).with_empty_span() + (Value::SingleQuotedString("xyz".to_owned().into())).with_empty_span() )), trim_where: None, trim_what: None, trim_characters: Some(vec![Expr::Value( - (Value::SingleQuotedString("a".to_owned())).with_empty_span() + (Value::SingleQuotedString("a".to_owned().into())).with_empty_span() )]), }, expr_from_projection(only(&select.projection)) @@ -4665,7 +4681,7 @@ *args, FunctionArguments::List(FunctionArgumentList { args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("email".to_string()).into() + Value::SingleQuotedString("email".to_string().into()).into() )))], clauses: vec![], duplicate_treatment: None @@ -4686,7 +4702,7 @@ *args, FunctionArguments::List(FunctionArgumentList { args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("\"Email\"".to_string()).into() + Value::SingleQuotedString("\"Email\"".to_string().into()).into() )))], clauses: vec![], duplicate_treatment: None @@ -4710,7 +4726,7 @@ *args, FunctionArguments::List(FunctionArgumentList { args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("alias1".to_string()).into() + Value::SingleQuotedString("alias1".to_string().into()).into() )))], clauses: vec![], duplicate_treatment: None @@ -4728,7 +4744,7 @@ ObjectName(vec![ObjectNamePart::Function(ObjectNamePartFunction { name: Ident::new("IDENTIFIER"), args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("tbl".to_string()).into() + Value::SingleQuotedString("tbl".to_string().into()).into() )))] })]) ); @@ -4745,7 +4761,7 @@ ObjectNamePartFunction { name: Ident::new("IDENTIFIER"), args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("db1.sc1".to_string()).into() + Value::SingleQuotedString("db1.sc1".to_string().into()).into() )))] } )])) @@ -4762,7 +4778,7 @@ ObjectName(vec![ObjectNamePart::Function(ObjectNamePartFunction { name: Ident::new("IDENTIFIER"), args: vec![FunctionArg::Unnamed(FunctionArgExpr::Expr(Expr::Value( - Value::SingleQuotedString("tbl".to_string()).into() + Value::SingleQuotedString("tbl".to_string().into()).into() )))] })]) );
diff --git a/tests/sqlparser_sqlite.rs b/tests/sqlparser_sqlite.rs index 10059c8..24bb454 100644 --- a/tests/sqlparser_sqlite.rs +++ b/tests/sqlparser_sqlite.rs
@@ -479,7 +479,7 @@ database: true, } => { assert_eq!(schema_name.value, "test"); - assert_eq!(literal_name, "test.db"); + assert_eq!(literal_name.value, "test.db"); } _ => unreachable!(), } @@ -633,7 +633,7 @@ op: BinaryOperator::Match, left: Box::new(Expr::Identifier(Ident::new("col"))), right: Box::new(Expr::Value( - (Value::SingleQuotedString("pattern".to_string())).with_empty_span() + (Value::SingleQuotedString("pattern".to_string().into())).with_empty_span() )) } ); @@ -648,7 +648,7 @@ op: BinaryOperator::Regexp, left: Box::new(Expr::Identifier(Ident::new("col"))), right: Box::new(Expr::Value( - (Value::SingleQuotedString("pattern".to_string())).with_empty_span() + (Value::SingleQuotedString("pattern".to_string().into())).with_empty_span() )) } ); @@ -673,7 +673,7 @@ op: BinaryOperator::Glob, left: Box::new(Expr::Identifier(Ident::new("col"))), right: Box::new(Expr::Value( - (Value::SingleQuotedString("pattern".to_string())).with_empty_span() + (Value::SingleQuotedString("pattern".to_string().into())).with_empty_span() )) } );