-
Notifications
You must be signed in to change notification settings - Fork 551
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
Support for single-quoted identifiers #1021
Conversation
b36514d
to
1cd3035
Compare
This does not support single-quoted table names, but supports the most common case of select tablename.'column' from tablename
1cd3035
to
e474232
Compare
Token::SingleQuotedString(s) => { | ||
id_parts.push(Ident::with_quote('\'', s)) | ||
} |
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 the most important part
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => { | ||
if self.peek_token().token == Token::Period { | ||
let mut id_parts: Vec<Ident> = vec![match t { | ||
Token::Word(w) => w.to_ident(), | ||
Token::SingleQuotedString(s) => Ident::with_quote('\'', s), | ||
_ => unreachable!(), // We matched above | ||
}]; | ||
|
||
while self.consume_token(&Token::Period) { | ||
let next_token = self.next_token(); | ||
match next_token.token { | ||
Token::Word(w) => id_parts.push(w.to_ident()), | ||
Token::SingleQuotedString(s) => { | ||
// SQLite has single-quoted identifiers | ||
id_parts.push(Ident::with_quote('\'', s)) | ||
} | ||
Token::Mul => { | ||
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts))); | ||
} | ||
_ => { | ||
return self | ||
.expected("an identifier or a '*' after '.'", next_token); | ||
} |
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 we can do later if you want, @alamb , together with support for single-quoted table names.
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 actually tried running the test in this PR without this change and it failed, so I am not quite sure what you are proposing to do later
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 PR supports select 't'.*
(which is tested) but not select 't'.my_column
.
What I was saying is that if you find that this is not clean, we can remove support for 't'.*
(and the associated part of the test) and re-add it later if/when we add general support for single-quoted table names.
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 it is ok -- thank you
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 looks good to me @lovasoa -- thank you. I had one question about your comment but otherwise I think this is ready to go
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => { | ||
if self.peek_token().token == Token::Period { | ||
let mut id_parts: Vec<Ident> = vec![match t { | ||
Token::Word(w) => w.to_ident(), | ||
Token::SingleQuotedString(s) => Ident::with_quote('\'', s), | ||
_ => unreachable!(), // We matched above | ||
}]; | ||
|
||
while self.consume_token(&Token::Period) { | ||
let next_token = self.next_token(); | ||
match next_token.token { | ||
Token::Word(w) => id_parts.push(w.to_ident()), | ||
Token::SingleQuotedString(s) => { | ||
// SQLite has single-quoted identifiers | ||
id_parts.push(Ident::with_quote('\'', s)) | ||
} | ||
Token::Mul => { | ||
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts))); | ||
} | ||
_ => { | ||
return self | ||
.expected("an identifier or a '*' after '.'", next_token); | ||
} |
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 actually tried running the test in this PR without this change and it failed, so I am not quite sure what you are proposing to do later
I took the liberty of merging up from main to resolve a conflict |
Co-authored-by: Andrew Lamb <[email protected]>
This does not support single-quoted table names, but supports the most common case of
fixes #1020