-
Notifications
You must be signed in to change notification settings - Fork 554
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
base: main
Are you sure you want to change the base?
Conversation
Relevant: apache#1402 SQLite version 3.43.2 2023-10-10 13:08:14 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> .mode box sqlite> .nullvalue NULL sqlite> SELECT $$, $$ABC$$, $ABC$, $ABC; ┌──────┬─────────┬───────┬──────┐ │ $$ │ $$ABC$$ │ $ABC$ │ $ABC │ ├──────┼─────────┼───────┼──────┤ │ NULL │ NULL │ NULL │ NULL │ └──────┴─────────┴───────┴──────┘
src/dialect/mod.rs
Outdated
@@ -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 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!
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.
Thanks @hansott! The changes look reasonable to me overall, left some comments
src/tokenizer.rs
Outdated
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 string, then `$$` is rather a placeholder. | |
if matches!(chars.peek(), Some('$')) && self.dialect.supports_dollar_quoted_string() { |
if that makes sense, figured we could mention in the comment what the condition implies?
src/tokenizer.rs
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
let next_is_dollar = matches!(chars.peek(), Some('$')); | |
if next_is_dollar && self.dialect.supports_dollar_quoted_string() { | |
if matches!(chars.peek(), Some('$')) && self.dialect.supports_dollar_quoted_string() { |
src/tokenizer.rs
Outdated
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
fn tokenize_dollar_placeholder_sqlite() { | |
fn tokenize_dollar_placeholder() { |
src/dialect/mod.rs
Outdated
@@ -636,6 +636,12 @@ 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 { |
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.
I wondering would it make more sense to flip the condition to e.g. supports_dollar_placeholder()
, setting that to true for sqlite and default false for the others? Thinking that might be the more conservative change of the two given that its the placeholder behavior that is more subtle/specific, (most of the other dialects technically don't support dollar quoted string so its less misleading if they don't have to explicitly flag otherwise)
@iffyio Addressed all your comments, great feedback 🥇 |
Relevant: #1402
Not sure if this is the best way to fix, open for feedback.