-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQLite: Allow dollar signs in placeholder names #1620
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -636,6 +636,10 @@ pub trait Dialect: Debug + Any { | |
false | ||
} | ||
|
||
fn supports_dollar_quoted_string(&self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondering would it make more sense to flip the condition to e.g. |
||
true | ||
} | ||
|
||
/// Does the dialect support with clause in create index statement? | ||
/// e.g. `CREATE INDEX idx ON t WITH (key = value, key2)` | ||
fn supports_create_index_with_clause(&self) -> bool { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1523,7 +1523,9 @@ impl<'a> Tokenizer<'a> { | |||||||||||
|
||||||||||||
chars.next(); | ||||||||||||
|
||||||||||||
if let Some('$') = chars.peek() { | ||||||||||||
// Check if the second character is a dollar sign | ||||||||||||
let next_is_dollar = matches!(chars.peek(), Some('$')); | ||||||||||||
if next_is_dollar && self.dialect.supports_dollar_quoted_string() { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
if that makes sense, figured we could mention in the comment what the condition implies? |
||||||||||||
chars.next(); | ||||||||||||
|
||||||||||||
let mut is_terminated = false; | ||||||||||||
|
@@ -1557,10 +1559,13 @@ impl<'a> Tokenizer<'a> { | |||||||||||
}; | ||||||||||||
} else { | ||||||||||||
value.push_str(&peeking_take_while(chars, |ch| { | ||||||||||||
ch.is_alphanumeric() || ch == '_' | ||||||||||||
ch.is_alphanumeric() | ||||||||||||
|| ch == '_' | ||||||||||||
|| matches!(ch, '$' if !self.dialect.supports_dollar_quoted_string()) | ||||||||||||
})); | ||||||||||||
|
||||||||||||
if let Some('$') = chars.peek() { | ||||||||||||
let next_is_dollar = matches!(chars.peek(), Some('$')); | ||||||||||||
if next_is_dollar && self.dialect.supports_dollar_quoted_string() { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
chars.next(); | ||||||||||||
|
||||||||||||
'searching_for_end: loop { | ||||||||||||
|
@@ -2151,7 +2156,7 @@ fn take_char_from_hex_digits( | |||||||||||
mod tests { | ||||||||||||
use super::*; | ||||||||||||
use crate::dialect::{ | ||||||||||||
BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect, | ||||||||||||
BigQueryDialect, ClickHouseDialect, HiveDialect, MsSqlDialect, MySqlDialect, SQLiteDialect, | ||||||||||||
}; | ||||||||||||
use core::fmt::Debug; | ||||||||||||
|
||||||||||||
|
@@ -2604,6 +2609,30 @@ mod tests { | |||||||||||
); | ||||||||||||
} | ||||||||||||
|
||||||||||||
#[test] | ||||||||||||
fn tokenize_dollar_placeholder_sqlite() { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
let sql = String::from("SELECT $$, $$ABC$$, $ABC$, $ABC"); | ||||||||||||
let dialect = SQLiteDialect {}; | ||||||||||||
let tokens = Tokenizer::new(&dialect, &sql).tokenize().unwrap(); | ||||||||||||
assert_eq!( | ||||||||||||
tokens, | ||||||||||||
vec![ | ||||||||||||
Token::make_keyword("SELECT"), | ||||||||||||
Token::Whitespace(Whitespace::Space), | ||||||||||||
Token::Placeholder("$$".into()), | ||||||||||||
Token::Comma, | ||||||||||||
Token::Whitespace(Whitespace::Space), | ||||||||||||
Token::Placeholder("$$ABC$$".into()), | ||||||||||||
Token::Comma, | ||||||||||||
Token::Whitespace(Whitespace::Space), | ||||||||||||
Token::Placeholder("$ABC$".into()), | ||||||||||||
Token::Comma, | ||||||||||||
Token::Whitespace(Whitespace::Space), | ||||||||||||
Token::Placeholder("$ABC".into()), | ||||||||||||
] | ||||||||||||
); | ||||||||||||
} | ||||||||||||
|
||||||||||||
#[test] | ||||||||||||
fn tokenize_dollar_quoted_string_untagged() { | ||||||||||||
let sql = | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to add some documents for this method. (Just like others).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!