-
Notifications
You must be signed in to change notification settings - Fork 20
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
allow backticks in system and user variables #353
Conversation
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.
Looks good. Mostly just a question around the output formatting of what of the tests.
go/vt/sqlparser/parse_test.go
Outdated
}, | ||
{ | ||
input: "select @`user var`", | ||
output: "select `@``user var```", |
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 didn't understand the quoting in the output string here. Why does the @
get backtick quoted and why is there an extra "``" at the end of the statement? Seems like this output isn't valid MySQL SQL either.
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 did some digging and this comes from some weirdness in the formatID
method in ast.go
; the function didn't properly handle escaping user variables.
I fixed the function to do it better, but it shouldn't have any impact on what GMS sees.
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.
Nice! Thank you!
go/vt/sqlparser/token.go
Outdated
@@ -428,10 +428,25 @@ func (tkn *Tokenizer) scanIdentifier(firstByte byte, isDbSystemVariable bool) (i | |||
buffer.WriteByte(byte(tkn.lastChar)) | |||
tkn.next() | |||
} | |||
for isLetter(tkn.lastChar) || isDigit(tkn.lastChar) || (isDbSystemVariable && isCarat(tkn.lastChar)) { | |||
for isLetter(tkn.lastChar) || isDigit(tkn.lastChar) || (isDbSystemVariable && isCarat(tkn.lastChar)) /*|| (firstByte == '@' && isCarat(tkn.lastChar))*/ { |
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.
Take out this commented out condition?
This PR allows the use of backticks in system and user variables.
We are more lenient than MySQL when it comes to backticks in set statements.
For example, we allow
set @abc.
def= 10
, while MySQL throws an error.This is because we treat this as a qualified column identifer and automatically strip the backticks.
test bump dolthub/go-mysql-server#2548
fixes dolthub/dolt#8010