Skip to content
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

Merged
merged 3 commits into from
Jun 13, 2024
Merged

allow backticks in system and user variables #353

merged 3 commits into from
Jun 13, 2024

Conversation

jycor
Copy link

@jycor jycor commented Jun 13, 2024

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

@jycor jycor requested a review from zachmu as a code owner June 13, 2024 09:19
Copy link

@fulghum fulghum left a 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.

},
{
input: "select @`user var`",
output: "select `@``user var```",
Copy link

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.

Copy link
Author

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you!

@@ -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))*/ {
Copy link

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?

@jycor jycor merged commit d432e84 into main Jun 13, 2024
4 checks passed
@jycor jycor deleted the james/backticks branch June 13, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backtick escaping doesn't work for variables
2 participants