Skip to content

Commit

Permalink
supports_dollar_quoted_string -> supports_dollar_placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
hansott committed Dec 27, 2024
1 parent 87461b1 commit cfbac35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if this dialect allows dollar quoted strings
/// e.g. `SELECT $$Hello, world!$$` or `SELECT $tag$Hello, world!$tag$`
fn supports_dollar_quoted_string(&self) -> bool {
true
/// Returns true if this dialect allows dollar placeholders
/// e.g. `SELECT $var` (SQLite)
fn supports_dollar_placeholder(&self) -> bool {
false
}

/// Does the dialect support with clause in create index statement?
Expand Down
4 changes: 2 additions & 2 deletions src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Dialect for SQLiteDialect {
true
}

fn supports_dollar_quoted_string(&self) -> bool {
false
fn supports_dollar_placeholder(&self) -> bool {
true
}
}
14 changes: 7 additions & 7 deletions src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,8 @@ impl<'a> Tokenizer<'a> {

chars.next();

// 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() {
// If the dialect does not support dollar-quoted strings, then `$$` is rather a placeholder.
if matches!(chars.peek(), Some('$')) && !self.dialect.supports_dollar_placeholder() {
chars.next();

let mut is_terminated = false;
Expand Down Expand Up @@ -1561,11 +1560,12 @@ impl<'a> Tokenizer<'a> {
value.push_str(&peeking_take_while(chars, |ch| {
ch.is_alphanumeric()
|| ch == '_'
|| matches!(ch, '$' if !self.dialect.supports_dollar_quoted_string())
// Allow $ as a placeholder character if the dialect supports it
|| matches!(ch, '$' if self.dialect.supports_dollar_placeholder())
}));

let next_is_dollar = matches!(chars.peek(), Some('$'));
if next_is_dollar && self.dialect.supports_dollar_quoted_string() {
// If the dialect does not support dollar-quoted strings, don't look for the end delimiter.
if matches!(chars.peek(), Some('$')) && !self.dialect.supports_dollar_placeholder() {
chars.next();

'searching_for_end: loop {
Expand Down Expand Up @@ -2610,7 +2610,7 @@ mod tests {
}

#[test]
fn tokenize_dollar_placeholder_sqlite() {
fn tokenize_dollar_placeholder() {
let sql = String::from("SELECT $$, $$ABC$$, $ABC$, $ABC");
let dialect = SQLiteDialect {};
let tokens = Tokenizer::new(&dialect, &sql).tokenize().unwrap();
Expand Down

0 comments on commit cfbac35

Please sign in to comment.