mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-10-16 00:39:00 +00:00
Only support escape literals for Postgres, Redshift and generic dialect (#1674)
This commit is contained in:
parent
4f7154288e
commit
ef072be9e1
6 changed files with 69 additions and 2 deletions
|
@ -985,7 +985,7 @@ impl<'a> Tokenizer<'a> {
|
|||
}
|
||||
}
|
||||
// PostgreSQL accepts "escape" string constants, which are an extension to the SQL standard.
|
||||
x @ 'e' | x @ 'E' => {
|
||||
x @ 'e' | x @ 'E' if self.dialect.supports_string_escape_constant() => {
|
||||
let starting_loc = chars.location();
|
||||
chars.next(); // consume, to check the next char
|
||||
match chars.peek() {
|
||||
|
@ -3573,4 +3573,48 @@ mod tests {
|
|||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_string_escape_constant_not_supported() {
|
||||
all_dialects_where(|dialect| !dialect.supports_string_escape_constant()).tokenizes_to(
|
||||
"select e'...'",
|
||||
vec![
|
||||
Token::make_keyword("select"),
|
||||
Token::Whitespace(Whitespace::Space),
|
||||
Token::make_word("e", None),
|
||||
Token::SingleQuotedString("...".to_string()),
|
||||
],
|
||||
);
|
||||
|
||||
all_dialects_where(|dialect| !dialect.supports_string_escape_constant()).tokenizes_to(
|
||||
"select E'...'",
|
||||
vec![
|
||||
Token::make_keyword("select"),
|
||||
Token::Whitespace(Whitespace::Space),
|
||||
Token::make_word("E", None),
|
||||
Token::SingleQuotedString("...".to_string()),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_string_escape_constant_supported() {
|
||||
all_dialects_where(|dialect| dialect.supports_string_escape_constant()).tokenizes_to(
|
||||
"select e'\\''",
|
||||
vec![
|
||||
Token::make_keyword("select"),
|
||||
Token::Whitespace(Whitespace::Space),
|
||||
Token::EscapedStringLiteral("'".to_string()),
|
||||
],
|
||||
);
|
||||
|
||||
all_dialects_where(|dialect| dialect.supports_string_escape_constant()).tokenizes_to(
|
||||
"select E'\\''",
|
||||
vec![
|
||||
Token::make_keyword("select"),
|
||||
Token::Whitespace(Whitespace::Space),
|
||||
Token::EscapedStringLiteral("'".to_string()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue