-
Notifications
You must be signed in to change notification settings - Fork 601
fix: Handle double quotes inside quoted identifiers correctly #411
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
Conversation
This fixes apache#410 for standard SQL, however I don't know enough about other dialects to know if they handle this differently. May need more extensive testing as well.
4ca1db4
to
113722e
Compare
Pull Request Test Coverage Report for Build 1807104062
💛 - Coveralls |
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 @Marwes -- this is looking good. I think with a few more tests this would be good to go
#[test] | ||
fn parse_quoted_identifier() { | ||
pg_and_generic().verified_stmt(r#"SELECT "quoted "" ident""#); | ||
} |
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.
This is definitely how postgres handles things
alamb=# SELECT "quoted "" ident" from t1;
ERROR: column "quoted " ident" does not exist
LINE 1: SELECT "quoted "" ident" from t1;
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.
However, msql treats this differently
Database changed
mysql> SELECT "quoted "" ident" from t1;
+----------------+
| quoted " ident |
+----------------+
| quoted " ident |
| quoted " ident |
| quoted " ident |
| quoted " ident |
| quoted " ident |
+----------------+
5 rows in set (0.00 sec)
mysql> SELECT "quoted ident" from t1;
+---------------+
| quoted ident |
+---------------+
| quoted ident |
| quoted ident |
| quoted ident |
| quoted ident |
| quoted ident |
+---------------+
5 rows in set (0.00 sec)
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.
"
is used for strings in mysql unless ANSI_QUOTES
is enabled https://dev.mysql.com/doc/refman/8.0/en/identifiers.html . Neither double quoted strings or ANSI_QUOTES
seems implemented in this crate and I don't think it is up to this PR to fix that.
@@ -834,6 +834,11 @@ fn parse_comments() { | |||
} | |||
} | |||
|
|||
#[test] | |||
fn parse_quoted_identifier() { | |||
pg_and_generic().verified_stmt(r#"SELECT "quoted "" ident""#); |
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.
perhaps we can add a test for dialects (e.g. mysql) that this isn't parsed as an identifier?
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 added a test for ` quoted strings in mysql
src/tokenizer.rs
Outdated
@@ -418,8 +418,26 @@ impl<'a> Tokenizer<'a> { | |||
quote_start if self.dialect.is_delimited_identifier_start(quote_start) => { | |||
chars.next(); // consume the opening quote | |||
let quote_end = Word::matching_end_quote(quote_start); | |||
let s = peeking_take_while(chars, |ch| ch != quote_end); | |||
if chars.next() == Some(quote_end) { | |||
let mut last_char = None; |
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 think this code would be easier to understand if it were pulled out into its own function (peeking_take_while_ident
?) which could be unit tested, to ensure it handles cases such as
foo "" bar ""
foo bar""
Added `pretty_assertions` so that the `assert_eq!` in the tokenization is readable
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.
Thank you @Marwes
I hope to work through some various other PRs that are open this week and make a release later in the week |
Pull Request Test Coverage Report for Build 1806179475Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
This fixes #410 for standard SQL, however I don't know enough about other dialects to know if they
handle this differently. May need more extensive testing as well.